Remove direct map from Xen
cover Remove direct map from Xen
From: Hongyan Xia <[email protected]>
Previously, Wei Liu has created the patch series to switch to alloc/map/unmap/free APIs for Xen page tables so that Xen page tables are mapped with map_domain_page(). This is the first step towards removing the direct map. I implemented patches on top of Wei's to remove the direct map completely.
In addition to Wei's, my patches:
- (Wei) implement a proper PMAP infrastructure for bootstrapping
- remove direct map code in map_domain_page() and use mapcache, use PMAP when mapcache not ready
- map/unmap xenheap allocations to the direct map region so that va<->pa macros still work
- install dummy mappings (no permissions, INVALID_MFN) instead of actual 1:1 mappings during boot, so the direct map no longer exists
- fix many places where code incorrectly assumes a direct map
I have moderately tested the patches. I am able to boot into dom0, create/destroy PV/HVM guests and run XTF tests. Personally, I find it difficult to discover all places where it incorrectly assumes a direct map, so reviews and further testing are more than welcome.
Hongyan Xia (24):
x86/mm: fix leaks in map_xen_pagetable.
x86/pmap: break the loop in pmap APIs.
x86/domain_page: use PMAP when d/vcache is not ready. x86/domain_page: mapcache is no longer tied to pv.
mapcache: initialise the mapcache even for the idle domain.
x86: fix some wrong assumptions on direct map. Increase PMAP slots to
8.
x86/domain_page: remove direct map code and initialise idle mapcache.
page_alloc: actually do the mapping and unmapping on xenheap.
page_alloc: comments on (un)mapping pages in xenheap allocations. x86/smpboot: use xenheap pages for rpts in smpboot. x86/setup: start tearing down the direct map.
acpi: don't assume an always-mapped direct map in acpi allocations. x86/mm: Move vmap_to_mfn() to mm.c and rename to virt_to_mfn_walk(). x86/pv: refactor how building dom0 in PV handles domheap mappings. x86/mm: handle PSE early termination cases in virt_to_mfn_walk(). x86/setup: also clear the permission bits in the dummy 1:1 mapping.
x86: properly (un)map pages in restore_all_guests.
Revert "x86/smpboot: use xenheap pages for rpts in smpboot." Don't assume bootmem_region_list is mapped. Also fix a double unmap
bug.
x86/setup: Install dummy 1:1 mappings for all mem passed to
allocators.
x86/mm: optimise and properly unmap pages in virt_to_mfn_walk().
x86: deduplicate code a bit and fix an unmapping bug. x86/pmap: rewrite logic for locking.
x86/pv: fix a couple of direct map assumptions in dom0 building.
Wei Liu (60):
x86/mm: defer clearing page in virt_to_xen_lXe
x86: move some xen mm function declarations
x86: introduce a new set of APIs to manage Xen page tables x86/mm: introduce l{1,2}t local variables to map_pages_to_xen x86/mm: introduce l{1,2}t local variables to modify_xen_mappings x86/mm: map_pages_to_xen should have one exit path
x86/mm: add an end_of_loop label in map_pages_to_xen x86/mm: make sure there is one exit path for modify_xen_mappings x86/mm: add an end_of_loop label in modify_xen_mappings x86/mm: change pl2e to l2t in virt_to_xen_l2e
x86/mm: change pl1e to l1t in virt_to_xen_l1e
x86/mm: change pl3e to l3t in virt_to_xen_l3e
x86/mm: rewrite virt_to_xen_l3e
x86/mm: rewrite xen_to_virt_l2e
x86/mm: rewrite virt_to_xen_l1e
x86/mm: switch to new APIs in map_pages_to_xen
xxx fixup: avoid shadowing mfn
x86/mm: drop lXe_to_lYe invocations in map_pages_to_xen x86/mm: switch to new APIs in modify_xen_mappings
x86/mm: drop lXe_to_lYe invocations from modify_xen_mappings x86/mm: switch to new APIs in arch_init_memory
x86_64/mm: introduce pl2e in paging_init
x86_64/mm: switch to new APIs in paging_init
x86_64/mm: drop l4e_to_l3e invocation from paging_init x86_64/mm.c: remove code that serves no purpose in setup_m2p_table x86_64/mm: introduce pl2e in setup_m2p_table
x86_64/mm: switch to new APIs in setup_m2p_table x86_64/mm: drop lXe_to_lYe invocations from setup_m2p_table
efi: use new page table APIs in copy_mapping
efi: avoid using global variable in copy_mapping
efi: use new page table APIs in efi_init_memory
efi: add emacs block to boot.c
efi: switch EFI L4 table to use new APIs
x86/smpboot: add emacs block
x86/smpboot: clone_mapping should have one exit path x86/smpboot: switch pl3e to use new APIs in clone_mapping x86/smpboot: switch pl2e to use new APIs in clone_mapping x86/smpboot: switch pl1e to use new APIs in clone_mapping x86/smpboot: drop lXe_to_lYe invocations from cleanup_cpu_root_pgt
x86: switch root_pgt to mfn_t and use new APIs
x86/shim: map and unmap page tables in replace_va_mapping x86_64/mm: map and unmap page tables in m2p_mapped x86_64/mm: map and unmap page tables in share_hotadd_m2p_table x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping x86_64/mm: map and unmap page tables in destroy_m2p_mapping x86_64/mm: map and unmap page tables in setup_compat_m2p_table x86_64/mm: map and unmap page tables in cleanup_frame_table x86_64/mm: map and unmap page tables in subarch_init_memory x86_64/mm: map and unmap page tables in subarch_memory_op x86/smpboot: remove lXe_to_lYe in cleanup_cpu_root_pgt x86/pv: properly map and unmap page tables in mark_pv_pt_pages_rdonly x86/pv: properly map and unmap page table in dom0_construct_pv
x86: remove lXe_to_lYe in __start_xen
x86/mm: drop old page table APIs
x86: switch to use domheap page for page tables
x86/mm: drop _new suffix for page table APIs
x86: add Persistent Map (PMAP) infrastructure
x86: lift domain mapcache to arch_domain
x86: lift vcpu mapcache to arch_vcpu
x86/pv: domheap pages should be mapped while relocating initrd
xen/arch/x86/Makefile | 1 + xen/arch/x86/domain.c | 19 +- xen/arch/x86/domain_page.c | 71 ++--- xen/arch/x86/efi/runtime.h | 12 +- xen/arch/x86/mm.c | 549 ++++++++++++++++++++++++-------- xen/arch/x86/pmap.c | 121 +++++++ xen/arch/x86/pv/dom0_build.c | 107 +++++-- xen/arch/x86/pv/domain.c | 2 +- xen/arch/x86/pv/shim.c | 20 +- xen/arch/x86/setup.c | 28 +- xen/arch/x86/smpboot.c | 171 +++++++--- xen/arch/x86/x86_64/entry.S | 32 +- xen/arch/x86/x86_64/mm.c | 268 +++++++++++----- xen/common/efi/boot.c | 84 +++-- xen/common/efi/efi.h | 3 +- xen/common/efi/runtime.c | 8 +- xen/common/page_alloc.c | 37 ++- xen/common/schedule.c | 1 + xen/common/vmap.c | 2 +- xen/drivers/acpi/osl.c | 41 ++- xen/include/asm-arm/mm.h | 2 - xen/include/asm-x86/domain.h | 12 +- xen/include/asm-x86/fixmap.h | 3 + xen/include/asm-x86/mm.h | 20 ++ xen/include/asm-x86/page.h | 12 - xen/include/asm-x86/pmap.h | 10 + xen/include/asm-x86/processor.h | 2 - 27 files changed, 1211 insertions(+), 427 deletions(-) create mode 100644 xen/arch/x86/pmap.c create mode 100644 xen/include/asm-x86/pmap.h
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 1/84 x86/mm: defer clearing page in virt_to_xen_lXe
From: Wei Liu <[email protected]>
Defer the call to clear_page to the point when we're sure the page is going to become a page table.
This is a minor optimisation. No functional change.
--- xen/arch/x86/mm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/mm.c +3 -3
@@ -4879,13 +4879,13 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v)if ( !pl3e )return NULL ; -clear_page (pl3e);if ( locking )spin_lock (&map_pgdir_lock);if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) ) {l4_pgentry_t l4e =l4e_from_paddr (__pa (pl3e), __PAGE_HYPERVISOR); +clear_page (pl3e);l4e_write (pl4e, l4e);efi_update_l4_pgtable (l4_table_offset (v), l4e); pl3e =NULL ;
@@ -4914,11 +4914,11 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v)if ( !pl2e )return NULL ; -clear_page (pl2e);if ( locking )spin_lock (&map_pgdir_lock);if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) { +clear_page (pl2e);l3e_write (pl3e,l3e_from_paddr (__pa (pl2e), __PAGE_HYPERVISOR)); pl2e =NULL ; }
@@ -4947,11 +4947,11 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)if ( !pl1e )return NULL ; -clear_page (pl1e);if ( locking )spin_lock (&map_pgdir_lock);if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) { +clear_page (pl1e);l2e_write (pl2e,l2e_from_paddr (__pa (pl1e), __PAGE_HYPERVISOR)); pl1e =NULL ; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 2/84 x86: move some xen mm function declarations
In reply to [email protected]From: Wei Liu <[email protected]>
They were put into page.h but mm.h is more appropriate.
The real reason is that I will be adding some new functions which takes mfn_t. It turns out it is a bit difficult to do in page.h.
No functional change.
--- xen/include/asm-x86/mm.h | 5 +++++ xen/include/asm-x86/page.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-)
xen/include/asm-x86/mm.h +5 -0
@@ -630,4 +630,9 @@ int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id, unsigned long frame, unsigned int nr_frames, xen_pfn_t mfn_list[]); +/* Allocator functions for Xen pagetables. */ +void *alloc_xen_pagetable (void ); +void free_xen_pagetable (void *v); +l1_pgentry_t *virt_to_xen_l1e (unsigned long v); +#endif /* __ASM_X86_MM_H__ */
xen/include/asm-x86/page.h +0 -5
@@ -345,11 +345,6 @@ void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t);#ifndef __ASSEMBLY__ -/* Allocator functions for Xen pagetables. */ -void *alloc_xen_pagetable (void ); -void free_xen_pagetable (void *v); -l1_pgentry_t *virt_to_xen_l1e (unsigned long v); -/* Convert between PAT/PCD/PWT embedded in PTE flags and 3-bit cacheattr. */ static inline unsigned int pte_flags_to_cacheattr (unsigned int flags) {
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 3/84 x86: introduce a new set of APIs to manage Xen page tables
In reply to [email protected]From: Wei Liu <[email protected]>
We are going to switch to using domheap page for page tables. A new set of APIs is introduced to allocate, map, unmap and free pages for page tables.
The allocation and deallocation work on mfn_t but not page_info, because they are required to work even before frame table is set up.
Implement the old functions with the new ones. We will rewrite, site by site, other mm functions that manipulate page tables to use the new APIs.
Note these new APIs still use xenheap page underneath and no actual map and unmap is done so that we don't break xen half way. They will be switched to use domheap and dynamic mappings when usage of old APIs is eliminated.
No functional change intended in this patch.
--- xen/arch/x86/mm.c | 39 ++++++++++++++++++++++++++++++++++----- xen/include/asm-x86/mm.h | 11 +++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-)
xen/arch/x86/mm.c +34 -5
@@ -119,6 +119,7 @@#include <xen/efi.h> #include <xen/grant_table.h> #include <xen/hypercall.h> +#include <xen/mm.h> #include <asm/paging.h> #include <asm/shadow.h> #include <asm/page.h>
@@ -4847,22 +4848,50 @@ int mmcfg_intercept_write( }void *alloc_xen_pagetable (void ) +{ +mfn_t mfn; + + mfn =alloc_xen_pagetable_new (); +ASSERT (!mfn_eq (mfn,INVALID_MFN )); + +return map_xen_pagetable_new (mfn); +} + +void free_xen_pagetable (void *v) +{ +if ( system_state != SYS_STATE_early_boot ) +free_xen_pagetable_new (virt_to_mfn (v)); +} + +mfn_t alloc_xen_pagetable_new (void ) {if ( system_state != SYS_STATE_early_boot ) {void *ptr =alloc_xenheap_page ();BUG_ON (!hardware_domain && !ptr); -return ptr; +return virt_to_mfn (ptr); } -return mfn_to_virt (mfn_x (alloc_boot_pages (1 ,1 ))); +return alloc_boot_pages (1 ,1 ); } -void free_xen_pagetable (void *v) +void *map_xen_pagetable_new (mfn_t mfn) { -if ( system_state != SYS_STATE_early_boot ) -free_xenheap_page (v); +return mfn_to_virt (mfn_x (mfn)); +} + +/* v can point to an entry within a table or be NULL */ +void unmap_xen_pagetable_new (void *v) +{ +/* XXX still using xenheap page, no need to do anything. */ +} + +/* mfn can be INVALID_MFN */ +void free_xen_pagetable_new (mfn_t mfn) +{ +if ( system_state != SYS_STATE_early_boot && !mfn_eq (mfn,INVALID_MFN ) ) +free_xenheap_page (mfn_to_virt (mfn_x (mfn))); }static DEFINE_SPINLOCK (map_pgdir_lock);
xen/include/asm-x86/mm.h +11 -0
@@ -633,6 +633,17 @@ int arch_acquire_resource(struct domain *d, unsigned int type,/* Allocator functions for Xen pagetables. */ void *alloc_xen_pagetable (void );void free_xen_pagetable (void *v); +mfn_t alloc_xen_pagetable_new (void ); +void *map_xen_pagetable_new (mfn_t mfn); +void unmap_xen_pagetable_new (void *v); +void free_xen_pagetable_new (mfn_t mfn); + +#define UNMAP_XEN_PAGETABLE_NEW (ptr) \ + do { \ + unmap_xen_pagetable_new((ptr)); \ + (ptr) = NULL; \ + } while (0) +l1_pgentry_t *virt_to_xen_l1e (unsigned long v);#endif /* __ASM_X86_MM_H__ */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 4/84 x86/mm: introduce l{1, 2}t local variables to map_pages_to_xen
In reply to [email protected]From: Wei Liu <[email protected]>
The pl2e and pl1e variables are heavily (ab)used in that function. It is fine at the moment because all page tables are always mapped so there is no need to track the life time of each variable.
We will soon have the requirement to map and unmap page tables. We need to track the life time of each variable to avoid leakage.
Introduce some l{1,2}t variables with limited scope so that we can track life time of pointers to xen page tables more easily.
No functional change.
--- xen/arch/x86/mm.c | 75 ++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 33 deletions(-)
xen/arch/x86/mm.c +42 -33
@@ -5061,10 +5061,12 @@ int map_pages_to_xen( }else { - pl2e =l3e_to_l2e (ol3e); +l2_pgentry_t *l2t; + + l2t =l3e_to_l2e (ol3e);for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) { - ol2e = pl2e[i]; + ol2e = l2t[i];if ( !(l2e_get_flags (ol2e) & _PAGE_PRESENT) )continue ;if (l2e_get_flags (ol2e) & _PAGE_PSE )
@@ -5072,21 +5074,22 @@ int map_pages_to_xen(else {unsigned int j; +l1_pgentry_t *l1t; - pl1e =l2e_to_l1e (ol2e); + l1t =l2e_to_l1e (ol2e);for ( j =0 ; j <L1_PAGETABLE_ENTRIES ; j++ ) -flush_flags (l1e_get_flags (pl1e[j])); +flush_flags (l1e_get_flags (l1t[j])); } }flush_area (virt, flush_flags);for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) { - ol2e = pl2e[i]; + ol2e = l2t[i];if ( (l2e_get_flags (ol2e) & _PAGE_PRESENT) && !(l2e_get_flags (ol2e) & _PAGE_PSE) )free_xen_pagetable (l2e_to_l1e (ol2e)); } -free_xen_pagetable (pl2e); +free_xen_pagetable (l2t); } }
@@ -5102,6 +5105,7 @@ int map_pages_to_xen( {unsigned int flush_flags =FLUSH_TLB |FLUSH_ORDER (2 *PAGETABLE_ORDER ); +l2_pgentry_t *l2t;/* Skip this PTE if there is no change. */ if ( ((l3e_get_pfn(ol3e) & ~(L2_PAGETABLE_ENTRIES *
@@ -5123,12 +5127,12 @@ int map_pages_to_xen(continue ; } - pl2e =alloc_xen_pagetable (); -if ( pl2e ==NULL ) + l2t =alloc_xen_pagetable (); +if ( l2t ==NULL )return -ENOMEM ;for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) -l2e_write (pl2e + i, +l2e_write (l2t + i,l2e_from_pfn (l3e_get_pfn (ol3e) + (i <<PAGETABLE_ORDER ),l3e_get_flags (ol3e)));
@@ -5141,15 +5145,15 @@ int map_pages_to_xen(if ( (l3e_get_flags (*pl3e) & _PAGE_PRESENT) && (l3e_get_flags (*pl3e) & _PAGE_PSE) ) { -l3e_write_atomic (pl3e,l3e_from_mfn (virt_to_mfn (pl2e), +l3e_write_atomic (pl3e,l3e_from_mfn (virt_to_mfn (l2t), __PAGE_HYPERVISOR)); - pl2e =NULL ; + l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);flush_area (virt, flush_flags); -if ( pl2e ) -free_xen_pagetable (pl2e); +if ( l2t ) +free_xen_pagetable (l2t); } pl2e =virt_to_xen_l2e (virt);
@@ -5177,11 +5181,13 @@ int map_pages_to_xen( }else { - pl1e =l2e_to_l1e (ol2e); +l1_pgentry_t *l1t; + + l1t =l2e_to_l1e (ol2e);for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) -flush_flags (l1e_get_flags (pl1e[i])); +flush_flags (l1e_get_flags (l1t[i]));flush_area (virt, flush_flags); -free_xen_pagetable (pl1e); +free_xen_pagetable (l1t); } }
@@ -5203,6 +5209,7 @@ int map_pages_to_xen( {unsigned int flush_flags =FLUSH_TLB |FLUSH_ORDER (PAGETABLE_ORDER ); +l1_pgentry_t *l1t;/* Skip this PTE if there is no change. */ if ( (((l2e_get_pfn(*pl2e) & ~(L1_PAGETABLE_ENTRIES - 1)) +
@@ -5222,12 +5229,12 @@ int map_pages_to_xen( goto check_l3; } - pl1e =alloc_xen_pagetable (); -if ( pl1e ==NULL ) + l1t =alloc_xen_pagetable (); +if ( l1t ==NULL )return -ENOMEM ;for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) -l1e_write (&pl1e[i], +l1e_write (&l1t[i],l1e_from_pfn (l2e_get_pfn (*pl2e) + i,lNf_to_l1f (l2e_get_flags (*pl2e))));
@@ -5239,15 +5246,15 @@ int map_pages_to_xen(if ( (l2e_get_flags (*pl2e) & _PAGE_PRESENT) && (l2e_get_flags (*pl2e) & _PAGE_PSE) ) { -l2e_write_atomic (pl2e,l2e_from_mfn (virt_to_mfn (pl1e), +l2e_write_atomic (pl2e,l2e_from_mfn (virt_to_mfn (l1t), __PAGE_HYPERVISOR)); - pl1e =NULL ; + l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);flush_area (virt, flush_flags); -if ( pl1e ) -free_xen_pagetable (pl1e); +if ( l1t ) +free_xen_pagetable (l1t); } pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (virt);
@@ -5272,6 +5279,7 @@ int map_pages_to_xen( ((1u << PAGETABLE_ORDER) - 1)) == 0)) ) {unsigned long base_mfn; +l1_pgentry_t *l1t;if ( locking )spin_lock (&map_pgdir_lock);
@@ -5295,11 +5303,11 @@ int map_pages_to_xen( goto check_l3; } - pl1e =l2e_to_l1e (ol2e); - base_mfn =l1e_get_pfn (*pl1e) & ~(L1_PAGETABLE_ENTRIES -1 ); -for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++, pl1e++ ) -if ( (l1e_get_pfn (*pl1e) != (base_mfn + i)) || - (l1e_get_flags (*pl1e) != flags) ) + l1t =l2e_to_l1e (ol2e); + base_mfn =l1e_get_pfn (l1t[0 ]) & ~(L1_PAGETABLE_ENTRIES -1 ); +for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) +if ( (l1e_get_pfn (l1t[i]) != (base_mfn + i)) || + (l1e_get_flags (l1t[i]) != flags) )break ;if ( i ==L1_PAGETABLE_ENTRIES ) {
@@ -5325,6 +5333,7 @@ int map_pages_to_xen( ((1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1))) ) {unsigned long base_mfn; +l2_pgentry_t *l2t;if ( locking )spin_lock (&map_pgdir_lock);
@@ -5342,13 +5351,13 @@ int map_pages_to_xen(continue ; } - pl2e =l3e_to_l2e (ol3e); - base_mfn =l2e_get_pfn (*pl2e) & ~(L2_PAGETABLE_ENTRIES * + l2t =l3e_to_l2e (ol3e); + base_mfn =l2e_get_pfn (l2t[0 ]) & ~(L2_PAGETABLE_ENTRIES *L1_PAGETABLE_ENTRIES -1 ); -for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++, pl2e++ ) -if ( (l2e_get_pfn (*pl2e) != +for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) +if ( (l2e_get_pfn (l2t[i]) != (base_mfn + (i <<PAGETABLE_ORDER ))) || - (l2e_get_flags (*pl2e) !=l1f_to_lNf (flags)) ) + (l2e_get_flags (l2t[i]) !=l1f_to_lNf (flags)) )break ;if ( i ==L2_PAGETABLE_ENTRIES ) {
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 5/84 x86/mm: introduce l{1, 2}t local variables to modify_xen_mappings
In reply to [email protected]From: Wei Liu <[email protected]>
The pl2e and pl1e variables are heavily (ab)used in that function. It is fine at the moment because all page tables are always mapped so there is no need to track the life time of each variable.
We will soon have the requirement to map and unmap page tables. We need to track the life time of each variable to avoid leakage.
Introduce some l{1,2}t variables with limited scope so that we can track life time of pointers to xen page tables more easily.
No functional change.
--- xen/arch/x86/mm.c | 68 ++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 30 deletions(-)
xen/arch/x86/mm.c +38 -30
@@ -5428,6 +5428,8 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if (l3e_get_flags (*pl3e) & _PAGE_PSE ) { +l2_pgentry_t *l2t; +if (l2_table_offset (v) ==0 &&l1_table_offset (v) ==0 && ((e - v) >= (1UL <<L3_PAGETABLE_SHIFT )) )
@@ -5443,11 +5445,11 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) }/* PAGE1GB: shatter the superpage and fall through. */ - pl2e =alloc_xen_pagetable (); -if ( !pl2e ) + l2t =alloc_xen_pagetable (); +if ( !l2t )return -ENOMEM ;for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) -l2e_write (pl2e + i, +l2e_write (l2t + i,l2e_from_pfn (l3e_get_pfn (*pl3e) + (i <<PAGETABLE_ORDER ),l3e_get_flags (*pl3e)));
@@ -5456,14 +5458,14 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if ( (l3e_get_flags (*pl3e) & _PAGE_PRESENT) && (l3e_get_flags (*pl3e) & _PAGE_PSE) ) { -l3e_write_atomic (pl3e,l3e_from_mfn (virt_to_mfn (pl2e), +l3e_write_atomic (pl3e,l3e_from_mfn (virt_to_mfn (l2t), __PAGE_HYPERVISOR)); - pl2e =NULL ; + l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock); -if ( pl2e ) -free_xen_pagetable (pl2e); +if ( l2t ) +free_xen_pagetable (l2t); }/*
@@ -5497,12 +5499,14 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) }else { +l1_pgentry_t *l1t; +/* PSE: shatter the superpage and try again. */ - pl1e =alloc_xen_pagetable (); -if ( !pl1e ) + l1t =alloc_xen_pagetable (); +if ( !l1t )return -ENOMEM ;for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) -l1e_write (&pl1e[i], +l1e_write (&l1t[i],l1e_from_pfn (l2e_get_pfn (*pl2e) + i,l2e_get_flags (*pl2e) & ~_PAGE_PSE));if ( locking )
@@ -5510,19 +5514,19 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if ( (l2e_get_flags (*pl2e) & _PAGE_PRESENT) && (l2e_get_flags (*pl2e) & _PAGE_PSE) ) { -l2e_write_atomic (pl2e,l2e_from_mfn (virt_to_mfn (pl1e), +l2e_write_atomic (pl2e,l2e_from_mfn (virt_to_mfn (l1t), __PAGE_HYPERVISOR)); - pl1e =NULL ; + l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock); -if ( pl1e ) -free_xen_pagetable (pl1e); +if ( l1t ) +free_xen_pagetable (l1t); } }else { -l1_pgentry_t nl1e; +l1_pgentry_t nl1e, *l1t;/* * Ordinary 4kB mapping: The L2 entry has been verified to be
@@ -5569,9 +5573,9 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)continue ; } - pl1e =l2e_to_l1e (*pl2e); + l1t =l2e_to_l1e (*pl2e);for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) -if (l1e_get_intpte (pl1e[i]) !=0 ) +if (l1e_get_intpte (l1t[i]) !=0 )break ;if ( i ==L1_PAGETABLE_ENTRIES ) {
@@ -5580,7 +5584,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if ( locking )spin_unlock (&map_pgdir_lock);flush_area (NULL ,FLUSH_TLB_GLOBAL );/* flush before free */ -free_xen_pagetable (pl1e); +free_xen_pagetable (l1t); }else if ( locking )spin_unlock (&map_pgdir_lock);
@@ -5609,21 +5613,25 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)continue ; } - pl2e =l3e_to_l2e (*pl3e); -for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) -if (l2e_get_intpte (pl2e[i]) !=0 ) -break ; -if ( i ==L2_PAGETABLE_ENTRIES ) { -/* Empty: zap the L3E and free the L2 page. */ -l3e_write_atomic (pl3e,l3e_empty ()); -if ( locking ) +l2_pgentry_t *l2t; + + l2t =l3e_to_l2e (*pl3e); +for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) +if (l2e_get_intpte (l2t[i]) !=0 ) +break ; +if ( i ==L2_PAGETABLE_ENTRIES ) + { +/* Empty: zap the L3E and free the L2 page. */ +l3e_write_atomic (pl3e,l3e_empty ()); +if ( locking ) +spin_unlock (&map_pgdir_lock); +flush_area (NULL ,FLUSH_TLB_GLOBAL );/* flush before free */ +free_xen_pagetable (l2t); + } +else if ( locking )spin_unlock (&map_pgdir_lock); -flush_area (NULL ,FLUSH_TLB_GLOBAL );/* flush before free */ -free_xen_pagetable (pl2e); } -else if ( locking ) -spin_unlock (&map_pgdir_lock); }flush_area (NULL ,FLUSH_TLB_GLOBAL );
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 6/84 x86/mm: map_pages_to_xen should have one exit path
In reply to [email protected]From: Wei Liu <[email protected]>
We will soon rewrite the function to handle dynamically mapping and unmapping of page tables.
No functional change.
--- xen/arch/x86/mm.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)
xen/arch/x86/mm.c +27 -7
@@ -5014,9 +5014,11 @@ int map_pages_to_xen( unsigned int flags) {bool locking = system_state > SYS_STATE_boot; +l3_pgentry_t *pl3e, ol3e;l2_pgentry_t *pl2e, ol2e;l1_pgentry_t *pl1e, ol1e;unsigned int i; +int rc = -ENOMEM ;#define flush_flags (oldf) do { \ unsigned int o_ = (oldf); \
@@ -5034,10 +5036,13 @@ int map_pages_to_xen(while ( nr_mfns !=0 ) { -l3_pgentry_t ol3e, *pl3e =virt_to_xen_l3e (virt); + pl3e =virt_to_xen_l3e (virt);if ( !pl3e ) -return -ENOMEM ; + { +ASSERT (rc == -ENOMEM ); + goto out; + } ol3e = *pl3e; if ( cpu_has_page1gb &&
@@ -5129,7 +5134,10 @@ int map_pages_to_xen( l2t =alloc_xen_pagetable ();if ( l2t ==NULL ) -return -ENOMEM ; + { +ASSERT (rc == -ENOMEM ); + goto out; + }for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) l2e_write(l2t + i,
@@ -5158,7 +5166,10 @@ int map_pages_to_xen( pl2e =virt_to_xen_l2e (virt);if ( !pl2e ) -return -ENOMEM ; + { +ASSERT (rc == -ENOMEM ); + goto out; + } if ( ((((virt >> PAGE_SHIFT) | mfn_x(mfn)) & ((1u << PAGETABLE_ORDER) - 1)) == 0) &&
@@ -5203,7 +5214,10 @@ int map_pages_to_xen( { pl1e =virt_to_xen_l1e (virt);if ( pl1e ==NULL ) -return -ENOMEM ; + { +ASSERT (rc == -ENOMEM ); + goto out; + } } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) {
@@ -5231,7 +5245,10 @@ int map_pages_to_xen( l1t =alloc_xen_pagetable ();if ( l1t ==NULL ) -return -ENOMEM ; + { +ASSERT (rc == -ENOMEM ); + goto out; + }for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) l1e_write(&l1t[i],
@@ -5377,7 +5394,10 @@ int map_pages_to_xen(#undef flush_flags -return 0 ; + rc =0 ; + + out: +return rc; }int populate_pt_range (unsigned long virt,unsigned long nr_mfns)
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 7/84 x86/mm: add an end_of_loop label in map_pages_to_xen
In reply to [email protected]From: Wei Liu <[email protected]>
We will soon need to clean up mappings whenever the out most loop is ended. Add a new label and turn relevant continue's into goto's.
No functional change.
--- xen/arch/x86/mm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/mm.c +5 -4
@@ -5102,7 +5102,7 @@ int map_pages_to_xen(if ( !mfn_eq (mfn,INVALID_MFN ) ) mfn =mfn_add (mfn,1UL << (L3_PAGETABLE_SHIFT -PAGE_SHIFT )); nr_mfns -=1UL << (L3_PAGETABLE_SHIFT -PAGE_SHIFT ); -continue ; + goto end_of_loop; } if ( (l3e_get_flags(ol3e) & _PAGE_PRESENT) &&
@@ -5129,7 +5129,7 @@ int map_pages_to_xen(if ( !mfn_eq (mfn,INVALID_MFN ) ) mfn =mfn_add (mfn, i); nr_mfns -= i; -continue ; + goto end_of_loop; } l2t =alloc_xen_pagetable ();
@@ -5310,7 +5310,7 @@ int map_pages_to_xen( {if ( locking )spin_unlock (&map_pgdir_lock); -continue ; + goto end_of_loop; }if (l2e_get_flags (ol2e) & _PAGE_PSE )
@@ -5365,7 +5365,7 @@ int map_pages_to_xen( {if ( locking )spin_unlock (&map_pgdir_lock); -continue ; + goto end_of_loop; } l2t =l3e_to_l2e (ol3e);
@@ -5390,6 +5390,7 @@ int map_pages_to_xen(else if ( locking )spin_unlock (&map_pgdir_lock); } + end_of_loop:; }#undef flush_flags
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 8/84 x86/mm: make sure there is one exit path for modify_xen_mappings
In reply to [email protected]From: Wei Liu <[email protected]>
We will soon need to handle dynamically mapping / unmapping page tables in the said function.
No functional change.
--- xen/arch/x86/mm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
xen/arch/x86/mm.c +15 -3
@@ -5425,6 +5425,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)l1_pgentry_t *pl1e;unsigned int i;unsigned long v = s; +int rc = -ENOMEM ;/* Set of valid PTE bits which may be altered. */ #define FLAGS_MASK (_PAGE_NX|_PAGE_RW|_PAGE_PRESENT)
@@ -5468,7 +5469,11 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)/* PAGE1GB: shatter the superpage and fall through. */ l2t =alloc_xen_pagetable ();if ( !l2t ) -return -ENOMEM ; + { +ASSERT (rc == -ENOMEM ); + goto out; + } +for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) +
@@ -5525,7 +5530,11 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)/* PSE: shatter the superpage and try again. */ l1t =alloc_xen_pagetable ();if ( !l1t ) -return -ENOMEM ; + { +ASSERT (rc == -ENOMEM ); + goto out; + } +for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i,
@@ -5658,7 +5667,10 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)flush_area (NULL ,FLUSH_TLB_GLOBAL );#undef FLAGS_MASK -return 0 ; + rc =0 ; + + out: +return rc; }#undef flush_area
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 9/84 x86/mm: add an end_of_loop label in modify_xen_mappings
In reply to [email protected]From: Wei Liu <[email protected]>
We will soon need to clean up mappings whenever the out most loop is ended. Add a new label and turn relevant continue's into goto's.
No functional change.
--- xen/arch/x86/mm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
xen/arch/x86/mm.c +8 -7
@@ -5445,7 +5445,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) v +=1UL <<L3_PAGETABLE_SHIFT ; v &= ~((1UL <<L3_PAGETABLE_SHIFT ) -1 ); -continue ; + goto end_of_loop; }if (l3e_get_flags (*pl3e) & _PAGE_PSE )
@@ -5463,7 +5463,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)l3e_write_atomic (pl3e, nl3e); v +=1UL <<L3_PAGETABLE_SHIFT ; -continue ; + goto end_of_loop; }/* PAGE1GB: shatter the superpage and fall through. */
@@ -5507,7 +5507,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) v +=1UL <<L2_PAGETABLE_SHIFT ; v &= ~((1UL <<L2_PAGETABLE_SHIFT ) -1 ); -continue ; + goto end_of_loop; }if (l2e_get_flags (*pl2e) & _PAGE_PSE )
@@ -5581,7 +5581,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)* skip the empty&free check. */ if ( (nf & _PAGE_PRESENT) || ((v != e) && (l1_table_offset (v) !=0 )) ) -continue ; + goto end_of_loop;if ( locking )spin_lock (&map_pgdir_lock);
@@ -5600,7 +5600,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) {if ( locking )spin_unlock (&map_pgdir_lock); -continue ; + goto end_of_loop; } l1t =l2e_to_l1e (*pl2e);
@@ -5627,7 +5627,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)*/ if ( (nf & _PAGE_PRESENT) || ((v != e) && (l2_table_offset (v) +l1_table_offset (v) !=0 )) ) -continue ; + goto end_of_loop;if ( locking )spin_lock (&map_pgdir_lock);
@@ -5640,7 +5640,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) {if ( locking )spin_unlock (&map_pgdir_lock); -continue ; + goto end_of_loop; } {
@@ -5662,6 +5662,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)else if ( locking )spin_unlock (&map_pgdir_lock); } + end_of_loop:; }flush_area (NULL ,FLUSH_TLB_GLOBAL );
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 10/84 x86/mm: change pl2e to l2t in virt_to_xen_l2e
In reply to [email protected]From: Wei Liu <[email protected]>
We will need to have a variable named pl2e when we rewrite virt_to_xen_l2e. Change pl2e to l2t to reflect better its purpose. This will make reviewing later patch easier.
No functional change.
--- xen/arch/x86/mm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/mm.c +7 -7
@@ -4939,22 +4939,22 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v)if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) {bool locking = system_state > SYS_STATE_boot; -l2_pgentry_t *pl2e =alloc_xen_pagetable (); +l2_pgentry_t *l2t =alloc_xen_pagetable (); -if ( !pl2e ) +if ( !l2t )return NULL ;if ( locking )spin_lock (&map_pgdir_lock);if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) { -clear_page (pl2e); -l3e_write (pl3e,l3e_from_paddr (__pa (pl2e), __PAGE_HYPERVISOR)); - pl2e =NULL ; +clear_page (l2t); +l3e_write (pl3e,l3e_from_paddr (__pa (l2t), __PAGE_HYPERVISOR)); + l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock); -if ( pl2e ) -free_xen_pagetable (pl2e); +if ( l2t ) +free_xen_pagetable (l2t); }BUG_ON (l3e_get_flags (*pl3e) & _PAGE_PSE);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 11/84 x86/mm: change pl1e to l1t in virt_to_xen_l1e
In reply to [email protected]From: Wei Liu <[email protected]>
We will need to have a variable named pl1e when we rewrite virt_to_xen_l1e. Change pl1e to l1t to reflect better its purpose. This will make reviewing later patch easier.
No functional change.
--- xen/arch/x86/mm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/mm.c +7 -7
@@ -4972,22 +4972,22 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) {bool locking = system_state > SYS_STATE_boot; -l1_pgentry_t *pl1e =alloc_xen_pagetable (); +l1_pgentry_t *l1t =alloc_xen_pagetable (); -if ( !pl1e ) +if ( !l1t )return NULL ;if ( locking )spin_lock (&map_pgdir_lock);if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) { -clear_page (pl1e); -l2e_write (pl2e,l2e_from_paddr (__pa (pl1e), __PAGE_HYPERVISOR)); - pl1e =NULL ; +clear_page (l1t); +l2e_write (pl2e,l2e_from_paddr (__pa (l1t), __PAGE_HYPERVISOR)); + l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock); -if ( pl1e ) -free_xen_pagetable (pl1e); +if ( l1t ) +free_xen_pagetable (l1t); }BUG_ON (l2e_get_flags (*pl2e) & _PAGE_PSE);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 12/84 x86/mm: change pl3e to l3t in virt_to_xen_l3e
In reply to [email protected]From: Wei Liu <[email protected]>
We will need to have a variable named pl3e when we rewrite virt_to_xen_l3e. Change pl3e to l3t to reflect better its purpose. This will make reviewing later patch easier.
No functional change.
--- xen/arch/x86/mm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/mm.c +7 -7
@@ -4904,25 +4904,25 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v)if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) ) {bool locking = system_state > SYS_STATE_boot; -l3_pgentry_t *pl3e =alloc_xen_pagetable (); +l3_pgentry_t *l3t =alloc_xen_pagetable (); -if ( !pl3e ) +if ( !l3t )return NULL ;if ( locking )spin_lock (&map_pgdir_lock);if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) ) { -l4_pgentry_t l4e =l4e_from_paddr (__pa (pl3e), __PAGE_HYPERVISOR); +l4_pgentry_t l4e =l4e_from_paddr (__pa (l3t), __PAGE_HYPERVISOR); -clear_page (pl3e); +clear_page (l3t);l4e_write (pl4e, l4e);efi_update_l4_pgtable (l4_table_offset (v), l4e); - pl3e =NULL ; + l3t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock); -if ( pl3e ) -free_xen_pagetable (pl3e); +if ( l3t ) +free_xen_pagetable (l3t); }return l4e_to_l3e (*pl4e) +l3_table_offset (v);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 13/84 x86/mm: rewrite virt_to_xen_l3e
In reply to [email protected]From: Wei Liu <[email protected]>
Rewrite that function to use the new APIs. Modify its callers to unmap the pointer returned.
--- xen/arch/x86/mm.c | 61 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-)
xen/arch/x86/mm.c +48 -13
@@ -4896,45 +4896,70 @@ void free_xen_pagetable_new(mfn_t mfn)static DEFINE_SPINLOCK (map_pgdir_lock); +/* +* Given a virtual address, return a pointer to xen's L3 entry. Caller +* needs to unmap the pointer. +*/ static l3_pgentry_t *virt_to_xen_l3e (unsigned long v) {l4_pgentry_t *pl4e; +l3_pgentry_t *pl3e =NULL ; pl4e = &idle_pg_table[l4_table_offset (v)];if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) ) {bool locking = system_state > SYS_STATE_boot; -l3_pgentry_t *l3t =alloc_xen_pagetable (); +l3_pgentry_t *l3t; +mfn_t mfn; + + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) + goto out; + + l3t =map_xen_pagetable_new (mfn); -if ( !l3t ) -return NULL ;if ( locking )spin_lock (&map_pgdir_lock);if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) ) { -l4_pgentry_t l4e =l4e_from_paddr (__pa (l3t), __PAGE_HYPERVISOR); +l4_pgentry_t l4e =l4e_from_mfn (mfn, __PAGE_HYPERVISOR);clear_page (l3t);l4e_write (pl4e, l4e);efi_update_l4_pgtable (l4_table_offset (v), l4e); + pl3e = l3t +l3_table_offset (v); l3t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);if ( l3t ) -free_xen_pagetable (l3t); + { +ASSERT (!pl3e); +ASSERT (!mfn_eq (mfn,INVALID_MFN )); +UNMAP_XEN_PAGETABLE_NEW (l3t); +free_xen_pagetable_new (mfn); + } + } + +if ( !pl3e ) + { +ASSERT (l4e_get_flags (*pl4e) & _PAGE_PRESENT); + pl3e = (l3_pgentry_t *)map_xen_pagetable_new (l4e_get_mfn (*pl4e)) + +l3_table_offset (v); } -return l4e_to_l3e (*pl4e) +l3_table_offset (v); + out: +return pl3e; }static l2_pgentry_t *virt_to_xen_l2e (unsigned long v) {l3_pgentry_t *pl3e; +l2_pgentry_t *pl2e =NULL ; pl3e =virt_to_xen_l3e (v);if ( !pl3e ) -return NULL ; + goto out;if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) {
@@ -4942,7 +4967,8 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v)l2_pgentry_t *l2t =alloc_xen_pagetable ();if ( !l2t ) -return NULL ; + goto out; +if ( locking )spin_lock (&map_pgdir_lock);if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) )
@@ -4958,7 +4984,11 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) }BUG_ON (l3e_get_flags (*pl3e) & _PAGE_PSE); -return l3e_to_l2e (*pl3e) +l2_table_offset (v); + pl2e =l3e_to_l2e (*pl3e) +l2_table_offset (v); + + out: +UNMAP_XEN_PAGETABLE_NEW (pl3e); +return pl2e; }l1_pgentry_t *virt_to_xen_l1e (unsigned long v)
@@ -5014,7 +5044,7 @@ int map_pages_to_xen( unsigned int flags) {bool locking = system_state > SYS_STATE_boot; -l3_pgentry_t *pl3e, ol3e; +l3_pgentry_t *pl3e =NULL , ol3e;l2_pgentry_t *pl2e, ol2e;l1_pgentry_t *pl1e, ol1e;unsigned int i;
@@ -5390,7 +5420,8 @@ int map_pages_to_xen(else if ( locking )spin_unlock (&map_pgdir_lock); } - end_of_loop:; + end_of_loop: +UNMAP_XEN_PAGETABLE_NEW (pl3e); }#undef flush_flags
@@ -5398,6 +5429,7 @@ int map_pages_to_xen( rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc; }
@@ -5421,6 +5453,7 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns)int modify_xen_mappings (unsigned long s,unsigned long e,unsigned int nf) {bool locking = system_state > SYS_STATE_boot; +l3_pgentry_t *pl3e =NULL ;l2_pgentry_t *pl2e;l1_pgentry_t *pl1e;unsigned int i;
@@ -5436,7 +5469,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)while ( v < e ) { -l3_pgentry_t *pl3e =virt_to_xen_l3e (v); + pl3e =virt_to_xen_l3e (v);if ( !pl3e || !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) {
@@ -5662,7 +5695,8 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)else if ( locking )spin_unlock (&map_pgdir_lock); } - end_of_loop:; + end_of_loop: +UNMAP_XEN_PAGETABLE_NEW (pl3e); }flush_area (NULL ,FLUSH_TLB_GLOBAL );
@@ -5671,6 +5705,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 14/84 x86/mm: rewrite xen_to_virt_l2e
In reply to [email protected]From: Wei Liu <[email protected]>
Rewrite that function to use the new APIs. Modify its callers to unmap the pointer returned.
--- xen/arch/x86/mm.c | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-)
xen/arch/x86/mm.c +37 -9
@@ -4952,6 +4952,10 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v)return pl3e; } +/* +* Given a virtual address, return a pointer to xen's L2 entry. Caller +* needs to unmap the pointer. +*/ static l2_pgentry_t *virt_to_xen_l2e (unsigned long v) {l3_pgentry_t *pl3e;
@@ -4964,27 +4968,44 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v)if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) {bool locking = system_state > SYS_STATE_boot; -l2_pgentry_t *l2t =alloc_xen_pagetable (); +l2_pgentry_t *l2t; +mfn_t mfn; -if ( !l2t ) + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) goto out; + l2t =map_xen_pagetable_new (mfn); +if ( locking )spin_lock (&map_pgdir_lock);if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) {clear_page (l2t); -l3e_write (pl3e,l3e_from_paddr (__pa (l2t), __PAGE_HYPERVISOR)); +l3e_write (pl3e,l3e_from_mfn (mfn, __PAGE_HYPERVISOR)); + pl2e = l2t +l2_table_offset (v); l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock); +if ( l2t ) -free_xen_pagetable (l2t); + { +ASSERT (!pl2e); +ASSERT (!mfn_eq (mfn,INVALID_MFN )); +UNMAP_XEN_PAGETABLE_NEW (l2t); +free_xen_pagetable_new (mfn); + } }BUG_ON (l3e_get_flags (*pl3e) & _PAGE_PSE); - pl2e =l3e_to_l2e (*pl3e) +l2_table_offset (v); + +if ( !pl2e ) + { +ASSERT (l3e_get_flags (*pl3e) & _PAGE_PRESENT); + pl2e = (l2_pgentry_t *)map_xen_pagetable_new (l3e_get_mfn (*pl3e)) + +l2_table_offset (v); + } out:UNMAP_XEN_PAGETABLE_NEW (pl3e);
@@ -4994,10 +5015,11 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v)l1_pgentry_t *virt_to_xen_l1e (unsigned long v) {l2_pgentry_t *pl2e; +l1_pgentry_t *pl1e =NULL ; pl2e =virt_to_xen_l2e (v);if ( !pl2e ) -return NULL ; + goto out;if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) {
@@ -5005,7 +5027,7 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)l1_pgentry_t *l1t =alloc_xen_pagetable ();if ( !l1t ) -return NULL ; + goto out;if ( locking )spin_lock (&map_pgdir_lock);if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) )
@@ -5021,7 +5043,11 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) }BUG_ON (l2e_get_flags (*pl2e) & _PAGE_PSE); -return l2e_to_l1e (*pl2e) +l1_table_offset (v); + pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (v); + + out: +UNMAP_XEN_PAGETABLE_NEW (pl2e); +return pl1e; }/* Convert to from superpage-mapping flags for map_pages_to_xen(). */
@@ -5045,7 +5071,7 @@ int map_pages_to_xen( {bool locking = system_state > SYS_STATE_boot;l3_pgentry_t *pl3e =NULL , ol3e; -l2_pgentry_t *pl2e, ol2e; +l2_pgentry_t *pl2e =NULL , ol2e;l1_pgentry_t *pl1e, ol1e;unsigned int i;int rc = -ENOMEM ;
@@ -5421,6 +5447,7 @@ int map_pages_to_xen(spin_unlock (&map_pgdir_lock); } end_of_loop: +UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e); }
@@ -5429,6 +5456,7 @@ int map_pages_to_xen( rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 15/84 x86/mm: rewrite virt_to_xen_l1e
In reply to [email protected]From: Wei Liu <[email protected]>
Rewrite this function to use new APIs. Modify its callers to unmap the pointer returned.
--- xen/arch/x86/domain_page.c | 10 ++++++---- xen/arch/x86/mm.c | 30 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-)
xen/arch/x86/domain_page.c +6 -4
@@ -333,21 +333,23 @@ void unmap_domain_page_global(const void *ptr)mfn_t domain_page_map_to_mfn (const void *ptr) {unsigned long va = (unsigned long )ptr; -const l1_pgentry_t *pl1e; +l1_pgentry_t l1e;if ( va >=DIRECTMAP_VIRT_START )return _mfn (virt_to_mfn (ptr));if ( va >=VMAP_VIRT_START && va <VMAP_VIRT_END ) { - pl1e =virt_to_xen_l1e (va); +l1_pgentry_t *pl1e =virt_to_xen_l1e (va);BUG_ON (!pl1e); + l1e = *pl1e; +UNMAP_XEN_PAGETABLE_NEW (pl1e); }else {ASSERT (va >=MAPCACHE_VIRT_START && va <MAPCACHE_VIRT_END ); - pl1e = &__linear_l1_table[l1_linear_offset (va)]; + l1e = __linear_l1_table[l1_linear_offset (va)]; } -return l1e_get_mfn (*pl1e); +return l1e_get_mfn (l1e); }
xen/arch/x86/mm.c +25 -5
@@ -5024,26 +5024,44 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) {bool locking = system_state > SYS_STATE_boot; -l1_pgentry_t *l1t =alloc_xen_pagetable (); +l1_pgentry_t *l1t; +mfn_t mfn; -if ( !l1t ) + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) goto out; + + l1t =map_xen_pagetable_new (mfn); +if ( locking )spin_lock (&map_pgdir_lock);if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) {clear_page (l1t); -l2e_write (pl2e,l2e_from_paddr (__pa (l1t), __PAGE_HYPERVISOR)); +l2e_write (pl2e,l2e_from_mfn (mfn, __PAGE_HYPERVISOR)); + pl1e = l1t +l1_table_offset (v); l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock); +if ( l1t ) -free_xen_pagetable (l1t); + { +ASSERT (!pl1e); +ASSERT (!mfn_eq (mfn,INVALID_MFN )); +UNMAP_XEN_PAGETABLE_NEW (l1t); +free_xen_pagetable_new (mfn); + } }BUG_ON (l2e_get_flags (*pl2e) & _PAGE_PSE); - pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (v); + +if ( !pl1e ) + { +ASSERT (l2e_get_flags (*pl2e) & _PAGE_PRESENT); + pl1e = (l1_pgentry_t *)map_xen_pagetable_new (l2e_get_mfn (*pl2e)) + +l1_table_offset (v); + } out:UNMAP_XEN_PAGETABLE_NEW (pl2e);
@@ -5447,6 +5465,7 @@ int map_pages_to_xen(spin_unlock (&map_pgdir_lock); } end_of_loop: +UNMAP_XEN_PAGETABLE_NEW (pl1e);UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e); }
@@ -5456,6 +5475,7 @@ int map_pages_to_xen( rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl1e);UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 16/84 x86/mm: switch to new APIs in map_pages_to_xen
In reply to [email protected]From: Wei Liu <[email protected]>
Page tables allocated in that function should be mapped and unmapped now.
--- xen/arch/x86/mm.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
xen/arch/x86/mm.c +22 -9
@@ -5185,6 +5185,7 @@ int map_pages_to_xen(unsigned int flush_flags =FLUSH_TLB |FLUSH_ORDER (2 *PAGETABLE_ORDER );l2_pgentry_t *l2t; +mfn_t mfn;/* Skip this PTE if there is no change. */ if ( ((l3e_get_pfn(ol3e) & ~(L2_PAGETABLE_ENTRIES *
@@ -5206,13 +5207,15 @@ int map_pages_to_xen( goto end_of_loop; } - l2t =alloc_xen_pagetable (); -if ( l2t ==NULL ) + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) {ASSERT (rc == -ENOMEM ); goto out; } + l2t =map_xen_pagetable_new (mfn); +for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(ol3e) +
@@ -5227,15 +5230,18 @@ int map_pages_to_xen(if ( (l3e_get_flags (*pl3e) & _PAGE_PRESENT) && (l3e_get_flags (*pl3e) & _PAGE_PSE) ) { -l3e_write_atomic (pl3e,l3e_from_mfn (virt_to_mfn (l2t), - __PAGE_HYPERVISOR)); +l3e_write_atomic (pl3e,l3e_from_mfn (mfn, __PAGE_HYPERVISOR)); +UNMAP_XEN_PAGETABLE_NEW (l2t); l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);flush_area (virt, flush_flags);if ( l2t ) -free_xen_pagetable (l2t); + { +UNMAP_XEN_PAGETABLE_NEW (l2t); +free_xen_pagetable_new (mfn); + } } pl2e =virt_to_xen_l2e (virt);
@@ -5298,6 +5304,7 @@ int map_pages_to_xen(unsigned int flush_flags =FLUSH_TLB |FLUSH_ORDER (PAGETABLE_ORDER );l1_pgentry_t *l1t; +mfn_t mfn;/* Skip this PTE if there is no change. */ if ( (((l2e_get_pfn(*pl2e) & ~(L1_PAGETABLE_ENTRIES - 1)) +
@@ -5317,13 +5324,15 @@ int map_pages_to_xen( goto check_l3; } - l1t =alloc_xen_pagetable (); -if ( l1t ==NULL ) + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) {ASSERT (rc == -ENOMEM ); goto out; } + l1t =map_xen_pagetable_new (mfn); +for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i,
@@ -5337,15 +5346,19 @@ int map_pages_to_xen(if ( (l2e_get_flags (*pl2e) & _PAGE_PRESENT) && (l2e_get_flags (*pl2e) & _PAGE_PSE) ) { -l2e_write_atomic (pl2e,l2e_from_mfn (virt_to_mfn (l1t), +l2e_write_atomic (pl2e,l2e_from_mfn (mfn, __PAGE_HYPERVISOR)); +UNMAP_XEN_PAGETABLE_NEW (l1t); l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);flush_area (virt, flush_flags);if ( l1t ) -free_xen_pagetable (l1t); + { +UNMAP_XEN_PAGETABLE_NEW (l1t); +free_xen_pagetable_new (mfn); + } } pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (virt);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 17/84 xxx fixup: avoid shadowing mfn
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/mm.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
xen/arch/x86/mm.c +13 -12
@@ -5185,7 +5185,7 @@ int map_pages_to_xen(unsigned int flush_flags =FLUSH_TLB |FLUSH_ORDER (2 *PAGETABLE_ORDER );l2_pgentry_t *l2t; -mfn_t mfn; +mfn_t l2t_mfn;/* Skip this PTE if there is no change. */ if ( ((l3e_get_pfn(ol3e) & ~(L2_PAGETABLE_ENTRIES *
@@ -5207,14 +5207,14 @@ int map_pages_to_xen( goto end_of_loop; } - mfn =alloc_xen_pagetable_new (); -if (mfn_eq (mfn,INVALID_MFN ) ) + l2t_mfn =alloc_xen_pagetable_new (); +if (mfn_eq (l2t_mfn,INVALID_MFN ) ) {ASSERT (rc == -ENOMEM ); goto out; } - l2t =map_xen_pagetable_new (mfn); + l2t =map_xen_pagetable_new (l2t_mfn);for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) l2e_write(l2t + i,
@@ -5230,7 +5230,8 @@ int map_pages_to_xen(if ( (l3e_get_flags (*pl3e) & _PAGE_PRESENT) && (l3e_get_flags (*pl3e) & _PAGE_PSE) ) { -l3e_write_atomic (pl3e,l3e_from_mfn (mfn, __PAGE_HYPERVISOR)); +l3e_write_atomic (pl3e, +l3e_from_mfn (l2t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE_NEW (l2t); l2t =NULL ; }
@@ -5240,7 +5241,7 @@ int map_pages_to_xen(if ( l2t ) {UNMAP_XEN_PAGETABLE_NEW (l2t); -free_xen_pagetable_new (mfn); +free_xen_pagetable_new (l2t_mfn); } }
@@ -5304,7 +5305,7 @@ int map_pages_to_xen(unsigned int flush_flags =FLUSH_TLB |FLUSH_ORDER (PAGETABLE_ORDER );l1_pgentry_t *l1t; -mfn_t mfn; +mfn_t l1t_mfn;/* Skip this PTE if there is no change. */ if ( (((l2e_get_pfn(*pl2e) & ~(L1_PAGETABLE_ENTRIES - 1)) +
@@ -5324,14 +5325,14 @@ int map_pages_to_xen( goto check_l3; } - mfn =alloc_xen_pagetable_new (); -if (mfn_eq (mfn,INVALID_MFN ) ) + l1t_mfn =alloc_xen_pagetable_new (); +if (mfn_eq (l1t_mfn,INVALID_MFN ) ) {ASSERT (rc == -ENOMEM ); goto out; } - l1t =map_xen_pagetable_new (mfn); + l1t =map_xen_pagetable_new (l1t_mfn);for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) l1e_write(&l1t[i],
@@ -5346,7 +5347,7 @@ int map_pages_to_xen(if ( (l2e_get_flags (*pl2e) & _PAGE_PRESENT) && (l2e_get_flags (*pl2e) & _PAGE_PSE) ) { -l2e_write_atomic (pl2e,l2e_from_mfn (mfn, +l2e_write_atomic (pl2e,l2e_from_mfn (l1t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE_NEW (l1t); l1t =NULL ;
@@ -5357,7 +5358,7 @@ int map_pages_to_xen(if ( l1t ) {UNMAP_XEN_PAGETABLE_NEW (l1t); -free_xen_pagetable_new (mfn); +free_xen_pagetable_new (l1t_mfn); } }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 17/84] xxx fixup: avoid shadowing mfn
Quoted 2 lines · On Thu, Sep 26, 2019 at 10:45:40AM +0100, [email protected] wrote:
From: Wei Liu <[email protected]>
Please squash this patch to the previous patch.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 18/84 x86/mm: drop lXe_to_lYe invocations in map_pages_to_xen
In reply to [email protected]From: Wei Liu <[email protected]>
Map and unmap page tables where necessary.
--- xen/arch/x86/mm.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
xen/arch/x86/mm.c +29 -11
@@ -5141,8 +5141,10 @@ int map_pages_to_xen(else {l2_pgentry_t *l2t; +mfn_t l2t_mfn =l3e_get_mfn (ol3e); + + l2t =map_xen_pagetable_new (l2t_mfn); - l2t =l3e_to_l2e (ol3e);for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) { ol2e = l2t[i];
@@ -5154,10 +5156,12 @@ int map_pages_to_xen( {unsigned int j;l1_pgentry_t *l1t; +mfn_t l1t_mfn =l2e_get_mfn (ol2e); - l1t =l2e_to_l1e (ol2e); + l1t =map_xen_pagetable_new (l1t_mfn);for ( j =0 ; j <L1_PAGETABLE_ENTRIES ; j++ )flush_flags (l1e_get_flags (l1t[j])); +UNMAP_XEN_PAGETABLE_NEW (l1t); } }flush_area (virt, flush_flags);
@@ -5166,9 +5170,9 @@ int map_pages_to_xen( ol2e = l2t[i];if ( (l2e_get_flags (ol2e) & _PAGE_PRESENT) && !(l2e_get_flags (ol2e) & _PAGE_PSE) ) -free_xen_pagetable (l2e_to_l1e (ol2e)); +free_xen_pagetable_new (l2e_get_mfn (ol2e)); } -free_xen_pagetable (l2t); +free_xen_pagetable_new (l2t_mfn); } }
@@ -5274,12 +5278,14 @@ int map_pages_to_xen(else {l1_pgentry_t *l1t; +mfn_t l1t_mfn =l2e_get_mfn (ol2e); - l1t =l2e_to_l1e (ol2e); + l1t =map_xen_pagetable_new (l1t_mfn);for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ )flush_flags (l1e_get_flags (l1t[i]));flush_area (virt, flush_flags); -free_xen_pagetable (l1t); +UNMAP_XEN_PAGETABLE_NEW (l1t); +free_xen_pagetable_new (l1t_mfn); } }
@@ -5293,12 +5299,14 @@ int map_pages_to_xen(/* Normal page mapping. */ if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) { +/* XXX This forces page table to be populated */ pl1e =virt_to_xen_l1e (virt);if ( pl1e ==NULL ) {ASSERT (rc == -ENOMEM ); goto out; } +UNMAP_XEN_PAGETABLE_NEW (pl1e); }else if (l2e_get_flags (*pl2e) & _PAGE_PSE ) {
@@ -5362,9 +5370,11 @@ int map_pages_to_xen( } } - pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (virt); + pl1e =map_xen_pagetable_new (l2e_get_mfn ((*pl2e))); + pl1e +=l1_table_offset (virt); ol1e = *pl1e;l1e_write_atomic (pl1e,l1e_from_mfn (mfn, flags)); +UNMAP_XEN_PAGETABLE_NEW (pl1e);if ( (l1e_get_flags (ol1e) & _PAGE_PRESENT) ) {unsigned int flush_flags =FLUSH_TLB |FLUSH_ORDER (0 );
@@ -5385,6 +5395,7 @@ int map_pages_to_xen( {unsigned long base_mfn;l1_pgentry_t *l1t; +mfn_t l1t_mfn;if ( locking )spin_lock (&map_pgdir_lock);
@@ -5408,12 +5419,15 @@ int map_pages_to_xen( goto check_l3; } - l1t =l2e_to_l1e (ol2e); + l1t_mfn =l2e_get_mfn (ol2e); + l1t =map_xen_pagetable_new (l1t_mfn); + base_mfn =l1e_get_pfn (l1t[0 ]) & ~(L1_PAGETABLE_ENTRIES -1 );for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ )if ( (l1e_get_pfn (l1t[i]) != (base_mfn + i)) || (l1e_get_flags (l1t[i]) != flags) )break ; +UNMAP_XEN_PAGETABLE_NEW (l1t);if ( i ==L1_PAGETABLE_ENTRIES ) { l2e_write_atomic(pl2e, l2e_from_pfn(base_mfn,
@@ -5423,7 +5437,7 @@ int map_pages_to_xen(flush_area (virt -PAGE_SIZE ,FLUSH_TLB_GLOBAL |FLUSH_ORDER (PAGETABLE_ORDER )); -free_xen_pagetable (l2e_to_l1e (ol2e)); +free_xen_pagetable_new (l1t_mfn); }else if ( locking )spin_unlock (&map_pgdir_lock);
@@ -5439,6 +5453,7 @@ int map_pages_to_xen( {unsigned long base_mfn;l2_pgentry_t *l2t; +mfn_t l2t_mfn;if ( locking )spin_lock (&map_pgdir_lock);
@@ -5456,7 +5471,9 @@ int map_pages_to_xen( goto end_of_loop; } - l2t =l3e_to_l2e (ol3e); + l2t_mfn =l3e_get_mfn (ol3e); + l2t =map_xen_pagetable_new (l2t_mfn); + base_mfn =l2e_get_pfn (l2t[0 ]) & ~(L2_PAGETABLE_ENTRIES *L1_PAGETABLE_ENTRIES -1 );for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ )
@@ -5464,6 +5481,7 @@ int map_pages_to_xen( (base_mfn + (i << PAGETABLE_ORDER))) || (l2e_get_flags(l2t[i]) != l1f_to_lNf(flags)) )break ; +UNMAP_XEN_PAGETABLE_NEW (l2t);if ( i ==L2_PAGETABLE_ENTRIES ) { l3e_write_atomic(pl3e, l3e_from_pfn(base_mfn,
@@ -5473,7 +5491,7 @@ int map_pages_to_xen(flush_area (virt -PAGE_SIZE ,FLUSH_TLB_GLOBAL |FLUSH_ORDER (2 *PAGETABLE_ORDER )); -free_xen_pagetable (l3e_to_l2e (ol3e)); +free_xen_pagetable_new (l2t_mfn); }else if ( locking )spin_unlock (&map_pgdir_lock);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 19/84 x86/mm: switch to new APIs in modify_xen_mappings
In reply to [email protected]From: Wei Liu <[email protected]>
Page tables allocated in that function should be mapped and unmapped now.
--- xen/arch/x86/mm.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
xen/arch/x86/mm.c +22 -9
@@ -5564,6 +5564,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if (l3e_get_flags (*pl3e) & _PAGE_PSE ) {l2_pgentry_t *l2t; +mfn_t mfn; if ( l2_table_offset(v) == 0 && l1_table_offset(v) == 0 &&
@@ -5580,13 +5581,15 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) }/* PAGE1GB: shatter the superpage and fall through. */ - l2t =alloc_xen_pagetable (); -if ( !l2t ) + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) {ASSERT (rc == -ENOMEM ); goto out; } + l2t =map_xen_pagetable_new (mfn); +for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) +
@@ -5597,14 +5600,17 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if ( (l3e_get_flags (*pl3e) & _PAGE_PRESENT) && (l3e_get_flags (*pl3e) & _PAGE_PSE) ) { -l3e_write_atomic (pl3e,l3e_from_mfn (virt_to_mfn (l2t), - __PAGE_HYPERVISOR)); +l3e_write_atomic (pl3e,l3e_from_mfn (mfn, __PAGE_HYPERVISOR)); +UNMAP_XEN_PAGETABLE_NEW (l2t); l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);if ( l2t ) -free_xen_pagetable (l2t); + { +UNMAP_XEN_PAGETABLE_NEW (l2t); +free_xen_pagetable_new (mfn); + } }/*
@@ -5639,15 +5645,18 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)else {l1_pgentry_t *l1t; +mfn_t mfn;/* PSE: shatter the superpage and try again. */ - l1t =alloc_xen_pagetable (); -if ( !l1t ) + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) {ASSERT (rc == -ENOMEM ); goto out; } + l1t =map_xen_pagetable_new (mfn); +for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i,
@@ -5657,14 +5666,18 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if ( (l2e_get_flags (*pl2e) & _PAGE_PRESENT) && (l2e_get_flags (*pl2e) & _PAGE_PSE) ) { -l2e_write_atomic (pl2e,l2e_from_mfn (virt_to_mfn (l1t), +l2e_write_atomic (pl2e,l2e_from_mfn (mfn, __PAGE_HYPERVISOR)); +UNMAP_XEN_PAGETABLE_NEW (l1t); l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);if ( l1t ) -free_xen_pagetable (l1t); + { +UNMAP_XEN_PAGETABLE_NEW (l1t); +free_xen_pagetable_new (mfn); + } } }else
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 20/84 x86/mm: drop lXe_to_lYe invocations from modify_xen_mappings
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/mm.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
xen/arch/x86/mm.c +19 -9
@@ -5534,8 +5534,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) {bool locking = system_state > SYS_STATE_boot;l3_pgentry_t *pl3e =NULL ; -l2_pgentry_t *pl2e; -l1_pgentry_t *pl1e; +l2_pgentry_t *pl2e =NULL ;unsigned int i;unsigned long v = s;int rc = -ENOMEM ;
@@ -5617,7 +5616,8 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)* The L3 entry has been verified to be present, and we've dealt with * 1G pages as well, so the L2 table cannot require allocation. */ - pl2e =l3e_to_l2e (*pl3e) +l2_table_offset (v); + pl2e =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + pl2e +=l2_table_offset (v);if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) {
@@ -5682,14 +5682,16 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) }else { -l1_pgentry_t nl1e, *l1t; +l1_pgentry_t nl1e, *l1t, *pl1e; +mfn_t l1t_mfn;/* * Ordinary 4kB mapping: The L2 entry has been verified to be * present, and we've dealt with 2M pages as well, so the L1 table * cannot require allocation. */ - pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (v); + pl1e =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); + pl1e +=l1_table_offset (v);/* Confirm the caller isn't trying to create new mappings. */ if ( !(l1e_get_flags (*pl1e) & _PAGE_PRESENT) )
@@ -5700,6 +5702,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) (l1e_get_flags(*pl1e) & ~FLAGS_MASK) | nf);l1e_write_atomic (pl1e, nl1e); +UNMAP_XEN_PAGETABLE_NEW (pl1e); v +=PAGE_SIZE ;/*
@@ -5729,10 +5732,12 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) goto end_of_loop; } - l1t =l2e_to_l1e (*pl2e); + l1t_mfn =l2e_get_mfn (*pl2e); + l1t =map_xen_pagetable_new (l1t_mfn);for ( i =0 ; i <L1_PAGETABLE_ENTRIES ; i++ )if (l1e_get_intpte (l1t[i]) !=0 )break ; +UNMAP_XEN_PAGETABLE_NEW (l1t);if ( i ==L1_PAGETABLE_ENTRIES ) {/* Empty: zap the L2E and free the L1 page. */
@@ -5740,7 +5745,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if ( locking )spin_unlock (&map_pgdir_lock);flush_area (NULL ,FLUSH_TLB_GLOBAL );/* flush before free */ -free_xen_pagetable (l1t); +free_xen_pagetable_new (l1t_mfn); }else if ( locking )spin_unlock (&map_pgdir_lock);
@@ -5771,11 +5776,14 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) {l2_pgentry_t *l2t; +mfn_t l2t_mfn; - l2t =l3e_to_l2e (*pl3e); + l2t_mfn =l3e_get_mfn (*pl3e); + l2t =map_xen_pagetable_new (l2t_mfn);for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ )if (l2e_get_intpte (l2t[i]) !=0 )break ; +UNMAP_XEN_PAGETABLE_NEW (l2t);if ( i ==L2_PAGETABLE_ENTRIES ) {/* Empty: zap the L3E and free the L2 page. */
@@ -5783,12 +5791,13 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)if ( locking )spin_unlock (&map_pgdir_lock);flush_area (NULL ,FLUSH_TLB_GLOBAL );/* flush before free */ -free_xen_pagetable (l2t); +free_xen_pagetable_new (l2t_mfn); }else if ( locking )spin_unlock (&map_pgdir_lock); } end_of_loop: +UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e); }
@@ -5798,6 +5807,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 21/84 x86/mm: switch to new APIs in arch_init_memory
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/mm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
xen/arch/x86/mm.c +9 -6
@@ -353,19 +353,22 @@ void __init arch_init_memory(void)ASSERT (root_pgt_pv_xen_slots <ROOT_PAGETABLE_PV_XEN_SLOTS );if (l4_table_offset (split_va) ==l4_table_offset (split_va -1 ) ) { -l3_pgentry_t *l3tab =alloc_xen_pagetable (); +mfn_t l3tab_mfn =alloc_xen_pagetable_new (); -if ( l3tab ) +if ( !mfn_eq (l3tab_mfn,INVALID_MFN ) ) { -const l3_pgentry_t *l3idle = -l4e_to_l3e (idle_pg_table[l4_table_offset (split_va)]); +l3_pgentry_t *l3idle = +map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (split_va)])); +l3_pgentry_t *l3tab =map_xen_pagetable_new (l3tab_mfn);for ( i =0 ; i <l3_table_offset (split_va); ++i ) l3tab[i] = l3idle[i];for ( ; i <L3_PAGETABLE_ENTRIES ; ++i ) l3tab[i] =l3e_empty (); - split_l4e =l4e_from_mfn (virt_to_mfn (l3tab), - __PAGE_HYPERVISOR_RW); + split_l4e =l4e_from_mfn (l3tab_mfn, __PAGE_HYPERVISOR_RW); +UNMAP_XEN_PAGETABLE_NEW (l3idle); +UNMAP_XEN_PAGETABLE_NEW (l3tab); }else ++root_pgt_pv_xen_slots;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 22/84 x86_64/mm: introduce pl2e in paging_init
In reply to [email protected]From: Wei Liu <[email protected]>
Introduce pl2e so that we can use l2_ro_mpt to point to the page table itself.
No functional change.
--- xen/arch/x86/x86_64/mm.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
xen/arch/x86/x86_64/mm.c +10 -8
@@ -497,7 +497,7 @@ void __init paging_init(void)unsigned long i, mpt_size, va;unsigned int n, memflags;l3_pgentry_t *l3_ro_mpt; -l2_pgentry_t *l2_ro_mpt =NULL ; +l2_pgentry_t *pl2e =NULL , *l2_ro_mpt;struct page_info *l1_pg;/*
@@ -547,7 +547,7 @@ void __init paging_init(void) (L2_PAGETABLE_SHIFT - 3 + PAGE_SHIFT)));if ( cpu_has_page1gb && - !((unsigned long )l2_ro_mpt & ~PAGE_MASK ) && + !((unsigned long )pl2e & ~PAGE_MASK ) && (mpt_size >>L3_PAGETABLE_SHIFT ) > (i >>PAGETABLE_ORDER ) ) {unsigned int k, holes;
@@ -607,7 +607,7 @@ void __init paging_init(void)memset ((void *)(RDWR_MPT_VIRT_START + (i <<L2_PAGETABLE_SHIFT )),0xFF ,1UL <<L2_PAGETABLE_SHIFT ); } -if ( !((unsigned long )l2_ro_mpt & ~PAGE_MASK ) ) +if ( !((unsigned long )pl2e & ~PAGE_MASK ) ) {if ( (l2_ro_mpt =alloc_xen_pagetable ()) ==NULL ) goto nomem;
@@ -615,13 +615,14 @@ void __init paging_init(void)l3e_write (&l3_ro_mpt[l3_table_offset (va)],l3e_from_paddr (__pa (l2_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER)); + pl2e = l2_ro_mpt;ASSERT (!l2_table_offset (va)); }/* NB. Cannot be GLOBAL: guest user mode should not see it. */ if ( l1_pg ) -l2e_write (l2_ro_mpt,l2e_from_page ( +l2e_write (pl2e,l2e_from_page ( l1_pg,/*_PAGE_GLOBAL|*/ _PAGE_PSE|_PAGE_USER|_PAGE_PRESENT)); - l2_ro_mpt++; + pl2e++; }#undef CNT#undef MFN
@@ -637,7 +638,8 @@ void __init paging_init(void)clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )],l3e_from_paddr (__pa (l2_ro_mpt), __PAGE_HYPERVISOR_RO)); - l2_ro_mpt +=l2_table_offset (HIRO_COMPAT_MPT_VIRT_START ); + pl2e = l2_ro_mpt; + pl2e +=l2_table_offset (HIRO_COMPAT_MPT_VIRT_START );/* Allocate and map the compatibility mode machine-to-phys table. */ mpt_size = (mpt_size >>1 ) + (1UL << (L2_PAGETABLE_SHIFT -1 ));if ( mpt_size >RDWR_COMPAT_MPT_VIRT_END -RDWR_COMPAT_MPT_VIRT_START )
@@ -650,7 +652,7 @@ void __init paging_init(void) sizeof(*compat_machine_to_phys_mapping))BUILD_BUG_ON ((sizeof (*frame_table) & ~sizeof (*frame_table)) % \sizeof (*compat_machine_to_phys_mapping)); -for ( i =0 ; i < (mpt_size >>L2_PAGETABLE_SHIFT ); i++, l2_ro_mpt++ ) +for ( i =0 ; i < (mpt_size >>L2_PAGETABLE_SHIFT ); i++, pl2e++ ) { memflags =MEMF_node (phys_to_nid (i << (L2_PAGETABLE_SHIFT -2 +PAGE_SHIFT )));
@@ -672,7 +674,7 @@ void __init paging_init(void) (i << L2_PAGETABLE_SHIFT)), 0xFF, 1UL << L2_PAGETABLE_SHIFT);/* NB. Cannot be GLOBAL as the ptes get copied into per-VM space. */ -l2e_write (l2_ro_mpt,l2e_from_page (l1_pg, _PAGE_PSE|_PAGE_PRESENT)); +l2e_write (pl2e,l2e_from_page (l1_pg, _PAGE_PSE|_PAGE_PRESENT)); }#undef CNT#undef MFN
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 23/84 x86_64/mm: switch to new APIs in paging_init
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 48 ++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-)
xen/arch/x86/x86_64/mm.c +36 -12
@@ -496,9 +496,10 @@ void __init paging_init(void) {unsigned long i, mpt_size, va;unsigned int n, memflags; -l3_pgentry_t *l3_ro_mpt; -l2_pgentry_t *pl2e =NULL , *l2_ro_mpt; +l3_pgentry_t *l3_ro_mpt =NULL ; +l2_pgentry_t *pl2e =NULL , *l2_ro_mpt =NULL ;struct page_info *l1_pg; +mfn_t l3_ro_mpt_mfn, l2_ro_mpt_mfn;/* * We setup the L3s for 1:1 mapping if host support memory hotplug
@@ -511,22 +512,29 @@ void __init paging_init(void)if ( !(l4e_get_flags (idle_pg_table[l4_table_offset (va)]) & _PAGE_PRESENT) ) { -l3_pgentry_t *pl3t =alloc_xen_pagetable (); +l3_pgentry_t *pl3t; +mfn_t mfn; -if ( !pl3t ) + mfn =alloc_xen_pagetable_new (); +if (mfn_eq (mfn,INVALID_MFN ) ) goto nomem; + + pl3t =map_xen_pagetable_new (mfn);clear_page (pl3t);l4e_write (&idle_pg_table[l4_table_offset (va)], -l4e_from_paddr (__pa (pl3t), __PAGE_HYPERVISOR_RW)); +l4e_from_mfn (mfn, __PAGE_HYPERVISOR_RW)); +UNMAP_XEN_PAGETABLE_NEW (pl3t); } }/* Create user-accessible L2 directory to map the MPT for guests. */ -if ( (l3_ro_mpt =alloc_xen_pagetable ()) ==NULL ) + l3_ro_mpt_mfn =alloc_xen_pagetable_new (); +if (mfn_eq (l3_ro_mpt_mfn,INVALID_MFN ) ) goto nomem; + l3_ro_mpt =map_xen_pagetable_new (l3_ro_mpt_mfn);clear_page (l3_ro_mpt);l4e_write (&idle_pg_table[l4_table_offset (RO_MPT_VIRT_START )], -l4e_from_paddr (__pa (l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER)); +l4e_from_mfn (l3_ro_mpt_mfn, __PAGE_HYPERVISOR_RO | _PAGE_USER));/* * Allocate and map the machine-to-phys table.
@@ -609,12 +617,21 @@ void __init paging_init(void) }if ( !((unsigned long )pl2e & ~PAGE_MASK ) ) { -if ( (l2_ro_mpt =alloc_xen_pagetable ()) ==NULL ) +/* +* Unmap l2_ro_mpt, which could've been mapped in previous +* iteration. +*/ +unmap_xen_pagetable_new (l2_ro_mpt); + + l2_ro_mpt_mfn =alloc_xen_pagetable_new (); +if (mfn_eq (l2_ro_mpt_mfn,INVALID_MFN ) ) goto nomem; + + l2_ro_mpt =map_xen_pagetable_new (l2_ro_mpt_mfn);clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (va)], -l3e_from_paddr (__pa (l2_ro_mpt), - __PAGE_HYPERVISOR_RO | _PAGE_USER)); +l3e_from_mfn (l2_ro_mpt_mfn, + __PAGE_HYPERVISOR_RO | _PAGE_USER)); pl2e = l2_ro_mpt;ASSERT (!l2_table_offset (va)); }
@@ -626,18 +643,23 @@ void __init paging_init(void) }#undef CNT#undef MFN +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); +UNMAP_XEN_PAGETABLE_NEW (l3_ro_mpt);/* Create user-accessible L2 directory to map the MPT for compat guests. */ BUILD_BUG_ON (l4_table_offset (RDWR_MPT_VIRT_START ) !=l4_table_offset (HIRO_COMPAT_MPT_VIRT_START )); l3_ro_mpt =l4e_to_l3e (idle_pg_table[l4_table_offset (HIRO_COMPAT_MPT_VIRT_START )]); -if ( (l2_ro_mpt =alloc_xen_pagetable ()) ==NULL ) + + l2_ro_mpt_mfn =alloc_xen_pagetable_new (); +if (mfn_eq (l2_ro_mpt_mfn,INVALID_MFN ) ) goto nomem; + l2_ro_mpt =map_xen_pagetable_new (l2_ro_mpt_mfn); compat_idle_pg_table_l2 = l2_ro_mpt;clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )], -l3e_from_paddr (__pa (l2_ro_mpt), __PAGE_HYPERVISOR_RO)); +l3e_from_mfn (l2_ro_mpt_mfn, __PAGE_HYPERVISOR_RO)); pl2e = l2_ro_mpt; pl2e +=l2_table_offset (HIRO_COMPAT_MPT_VIRT_START );/* Allocate and map the compatibility mode machine-to-phys table. */
@@ -679,6 +701,8 @@ void __init paging_init(void)#undef CNT#undef MFN +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); + machine_to_phys_mapping_valid =1 ;/* Set up linear page table mapping. */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 24/84 x86_64/mm: drop l4e_to_l3e invocation from paging_init
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/x86_64/mm.c +5 -2
@@ -649,8 +649,10 @@ void __init paging_init(void)/* Create user-accessible L2 directory to map the MPT for compat guests. */ BUILD_BUG_ON (l4_table_offset (RDWR_MPT_VIRT_START ) !=l4_table_offset (HIRO_COMPAT_MPT_VIRT_START )); - l3_ro_mpt =l4e_to_l3e (idle_pg_table[l4_table_offset ( -HIRO_COMPAT_MPT_VIRT_START )]); + + l3_ro_mpt_mfn =l4e_get_mfn (idle_pg_table[l4_table_offset ( +HIRO_COMPAT_MPT_VIRT_START )]); + l3_ro_mpt =map_xen_pagetable_new (l3_ro_mpt_mfn); l2_ro_mpt_mfn =alloc_xen_pagetable_new ();if (mfn_eq (l2_ro_mpt_mfn,INVALID_MFN ) )
@@ -702,6 +704,7 @@ void __init paging_init(void)#undef MFNUNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); +UNMAP_XEN_PAGETABLE_NEW (l3_ro_mpt); machine_to_phys_mapping_valid =1 ;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 25/84 x86_64/mm.c: remove code that serves no purpose in setup_m2p_table
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 2 -- 1 file changed, 2 deletions(-)
xen/arch/x86/x86_64/mm.c +0 -2
@@ -480,8 +480,6 @@ static int setup_m2p_table(struct mem_hotadd_info *info)l2e_write (l2_ro_mpt,l2e_from_mfn (mfn,/*_PAGE_GLOBAL|*/ _PAGE_PSE|_PAGE_USER|_PAGE_PRESENT)); } -if ( !((unsigned long )l2_ro_mpt & ~PAGE_MASK ) ) - l2_ro_mpt =NULL ; i += (1UL << (L2_PAGETABLE_SHIFT -3 )); }#undef CNT
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 26/84 x86_64/mm: introduce pl2e in setup_m2p_table
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/x86_64/mm.c +5 -4
@@ -397,7 +397,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) {unsigned long i, va, smap, emap;unsigned int n; -l2_pgentry_t *l2_ro_mpt =NULL ; +l2_pgentry_t *pl2e =NULL , *l2_ro_mpt;l3_pgentry_t *l3_ro_mpt =NULL ;int ret =0 ;
@@ -458,7 +458,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) _PAGE_PSE));if (l3e_get_flags (l3_ro_mpt[l3_table_offset (va)]) & _PAGE_PRESENT ) - l2_ro_mpt =l3e_to_l2e (l3_ro_mpt[l3_table_offset (va)]) + + pl2e =l3e_to_l2e (l3_ro_mpt[l3_table_offset (va)]) +l2_table_offset (va);else {
@@ -473,11 +473,12 @@ static int setup_m2p_table(struct mem_hotadd_info *info)l3e_write (&l3_ro_mpt[l3_table_offset (va)],l3e_from_paddr (__pa (l2_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER)); - l2_ro_mpt +=l2_table_offset (va); + pl2e = l2_ro_mpt; + pl2e +=l2_table_offset (va); }/* NB. Cannot be GLOBAL: guest user mode should not see it. */ -l2e_write (l2_ro_mpt,l2e_from_mfn (mfn, +l2e_write (pl2e,l2e_from_mfn (mfn,/*_PAGE_GLOBAL|*/ _PAGE_PSE|_PAGE_USER|_PAGE_PRESENT)); } i += (1UL << (L2_PAGETABLE_SHIFT -3 ));
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 27/84 x86_64/mm: switch to new APIs in setup_m2p_table
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
xen/arch/x86/x86_64/mm.c +9 -5
@@ -397,9 +397,10 @@ static int setup_m2p_table(struct mem_hotadd_info *info) {unsigned long i, va, smap, emap;unsigned int n; -l2_pgentry_t *pl2e =NULL , *l2_ro_mpt; +l2_pgentry_t *pl2e =NULL , *l2_ro_mpt =NULL ;l3_pgentry_t *l3_ro_mpt =NULL ;int ret =0 ; +mfn_t l2_ro_mpt_mfn;ASSERT (l4e_get_flags (idle_pg_table[l4_table_offset (RO_MPT_VIRT_START )]) & _PAGE_PRESENT);
@@ -462,17 +463,19 @@ static int setup_m2p_table(struct mem_hotadd_info *info)l2_table_offset (va); else { - l2_ro_mpt =alloc_xen_pagetable (); -if ( !l2_ro_mpt ) +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); + l2_ro_mpt_mfn =alloc_xen_pagetable_new (); +if (mfn_eq (l2_ro_mpt_mfn,INVALID_MFN ) ) { ret = -ENOMEM ; goto error; } + l2_ro_mpt =map_xen_pagetable_new (l2_ro_mpt_mfn);clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (va)], -l3e_from_paddr (__pa (l2_ro_mpt), - __PAGE_HYPERVISOR_RO | _PAGE_USER)); +l3e_from_mfn (l2_ro_mpt_mfn, + __PAGE_HYPERVISOR_RO | _PAGE_USER)); pl2e = l2_ro_mpt; pl2e +=l2_table_offset (va); }
@@ -488,6 +491,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) ret =setup_compat_m2p_table (info); error: +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt);return ret; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 28/84 x86_64/mm: drop lXe_to_lYe invocations from setup_m2p_table
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
xen/arch/x86/x86_64/mm.c +12 -4
@@ -400,11 +400,13 @@ static int setup_m2p_table(struct mem_hotadd_info *info)l2_pgentry_t *pl2e =NULL , *l2_ro_mpt =NULL ;l3_pgentry_t *l3_ro_mpt =NULL ;int ret =0 ; -mfn_t l2_ro_mpt_mfn; +mfn_t l2_ro_mpt_mfn, l3_ro_mpt_mfn;ASSERT (l4e_get_flags (idle_pg_table[l4_table_offset (RO_MPT_VIRT_START )]) & _PAGE_PRESENT); - l3_ro_mpt =l4e_to_l3e (idle_pg_table[l4_table_offset (RO_MPT_VIRT_START )]); + l3_ro_mpt_mfn =l4e_get_mfn (idle_pg_table[l4_table_offset ( +RO_MPT_VIRT_START )]); + l3_ro_mpt =map_xen_pagetable_new (l3_ro_mpt_mfn); smap = (info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT -3 )) -1 ))); emap = ((info->epfn + ((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1 )) &
@@ -459,8 +461,13 @@ static int setup_m2p_table(struct mem_hotadd_info *info) _PAGE_PSE));if (l3e_get_flags (l3_ro_mpt[l3_table_offset (va)]) & _PAGE_PRESENT ) - pl2e =l3e_to_l2e (l3_ro_mpt[l3_table_offset (va)]) + -l2_table_offset (va); + { +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); + l2_ro_mpt_mfn =l3e_get_mfn (l3_ro_mpt[l3_table_offset (va)]); + l2_ro_mpt =map_xen_pagetable_new (l2_ro_mpt_mfn); +ASSERT (l2_ro_mpt); + pl2e = l2_ro_mpt +l2_table_offset (va); + }else {UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt);
@@ -492,6 +499,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) ret =setup_compat_m2p_table (info); error:UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); +UNMAP_XEN_PAGETABLE_NEW (l3_ro_mpt);return ret; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 29/84 efi: use new page table APIs in copy_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
After inspection ARM doesn't have alloc_xen_pagetable so this function is x86 only, which means it is safe for us to change.
---
XXX test this in gitlab ci to be sure.
--- xen/common/efi/boot.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
xen/common/efi/boot.c +11 -5
@@ -1440,16 +1440,22 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,continue ;if ( !(l4e_get_flags (l4e) & _PAGE_PRESENT) ) { - l3dst =alloc_xen_pagetable (); -BUG_ON (!l3dst); +mfn_t l3t_mfn; + + l3t_mfn =alloc_xen_pagetable_new (); +BUG_ON (mfn_eq (l3t_mfn,INVALID_MFN )); + l3dst =map_xen_pagetable_new (l3t_mfn);clear_page (l3dst); efi_l4_pgtable[l4_table_offset (mfn <<PAGE_SHIFT )] = -l4e_from_paddr (virt_to_maddr (l3dst), __PAGE_HYPERVISOR); +l4e_from_mfn (l3t_mfn, __PAGE_HYPERVISOR); }else - l3dst =l4e_to_l3e (l4e); - l3src =l4e_to_l3e (idle_pg_table[l4_table_offset (va)]); + l3dst =map_xen_pagetable_new (l4e_get_mfn (l4e)); + l3src =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (va)])); l3dst[l3_table_offset (mfn <<PAGE_SHIFT )] = l3src[l3_table_offset (va)]; +UNMAP_XEN_PAGETABLE_NEW (l3src); +UNMAP_XEN_PAGETABLE_NEW (l3dst); } }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 30/84 efi: avoid using global variable in copy_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
We will soon switch efi_l4_table to use ephemeral mapping. Make copy_mapping take a pointer to the mapping instead of using the global variable.
No functional change intended.
--- xen/common/efi/boot.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
xen/common/efi/boot.c +6 -5
@@ -1423,7 +1423,8 @@ static int __init parse_efi_param(const char *s)custom_param ("efi" , parse_efi_param);#ifndef USE_SET_VIRTUAL_ADDRESS_MAP -static __init void copy_mapping (unsigned long mfn,unsigned long end, +static __init void copy_mapping (l4_pgentry_t *l4, +unsigned long mfn,unsigned long end,bool (*is_valid)(unsigned long smfn,unsigned long emfn)) {
@@ -1431,7 +1432,7 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,for ( ; mfn < end; mfn = next ) { -l4_pgentry_t l4e = efi_l4_pgtable[l4_table_offset (mfn <<PAGE_SHIFT )]; +l4_pgentry_t l4e = l4[l4_table_offset (mfn <<PAGE_SHIFT )];l3_pgentry_t *l3src, *l3dst;unsigned long va = (unsigned long )mfn_to_virt (mfn);
@@ -1446,7 +1447,7 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,BUG_ON (mfn_eq (l3t_mfn,INVALID_MFN )); l3dst =map_xen_pagetable_new (l3t_mfn);clear_page (l3dst); - efi_l4_pgtable[l4_table_offset (mfn <<PAGE_SHIFT )] = + l4[l4_table_offset (mfn <<PAGE_SHIFT )] =l4e_from_mfn (l3t_mfn, __PAGE_HYPERVISOR); }else
@@ -1606,7 +1607,7 @@ void __init efi_init_memory(void)BUG_ON (!efi_l4_pgtable);clear_page (efi_l4_pgtable); -copy_mapping (0 , max_page, ram_range_valid); +copy_mapping (efi_l4_pgtable,0 , max_page, ram_range_valid);/* Insert non-RAM runtime mappings inside the direct map. */ for ( i =0 ; i < efi_memmap_size; i += efi_mdesc_size )
@@ -1619,7 +1620,7 @@ void __init efi_init_memory(void) desc->Type == EfiBootServicesData))) && desc->VirtualStart != INVALID_VIRTUAL_ADDRESS && desc->VirtualStart != desc->PhysicalStart ) -copy_mapping (PFN_DOWN (desc->PhysicalStart), +copy_mapping (efi_l4_pgtable,PFN_DOWN (desc->PhysicalStart),PFN_UP (desc->PhysicalStart + (desc->NumberOfPages <<EFI_PAGE_SHIFT )), rt_range_valid);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 31/84 efi: use new page table APIs in efi_init_memory
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/common/efi/boot.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-)
xen/common/efi/boot.c +27 -12
@@ -1637,39 +1637,50 @@ void __init efi_init_memory(void)if ( !(l4e_get_flags (l4e) & _PAGE_PRESENT) ) { - pl3e =alloc_xen_pagetable (); -BUG_ON (!pl3e); +mfn_t l3t_mfn; + + l3t_mfn =alloc_xen_pagetable_new (); +BUG_ON (mfn_eq (l3t_mfn,INVALID_MFN )); + pl3e =map_xen_pagetable_new (l3t_mfn);clear_page (pl3e); efi_l4_pgtable[l4_table_offset (addr)] = -l4e_from_paddr (virt_to_maddr (pl3e), __PAGE_HYPERVISOR); +l4e_from_mfn (l3t_mfn, __PAGE_HYPERVISOR); }else - pl3e =l4e_to_l3e (l4e); + pl3e =map_xen_pagetable_new (l4e_get_mfn (l4e)); pl3e +=l3_table_offset (addr); +if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) { - pl2e =alloc_xen_pagetable (); -BUG_ON (!pl2e); +mfn_t l2t_mfn; + + l2t_mfn =alloc_xen_pagetable_new (); +BUG_ON (mfn_eq (l2t_mfn,INVALID_MFN )); + pl2e =map_xen_pagetable_new (l2t_mfn);clear_page (pl2e); - *pl3e =l3e_from_paddr (virt_to_maddr (pl2e), __PAGE_HYPERVISOR); + *pl3e =l3e_from_mfn (l2t_mfn, __PAGE_HYPERVISOR); }else {BUG_ON (l3e_get_flags (*pl3e) & _PAGE_PSE); - pl2e =l3e_to_l2e (*pl3e); + pl2e =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); } pl2e +=l2_table_offset (addr); +if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) { - l1t =alloc_xen_pagetable (); -BUG_ON (!l1t); +mfn_t l1t_mfn; + + l1t_mfn =alloc_xen_pagetable_new (); +BUG_ON (mfn_eq (l1t_mfn,INVALID_MFN )); + l1t =map_xen_pagetable_new (l1t_mfn);clear_page (l1t); - *pl2e =l2e_from_paddr (virt_to_maddr (l1t), __PAGE_HYPERVISOR); + *pl2e =l2e_from_mfn (l1t_mfn, __PAGE_HYPERVISOR); }else {BUG_ON (l2e_get_flags (*pl2e) & _PAGE_PSE); - l1t =l2e_to_l1e (*pl2e); + l1t =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); } for ( i = l1_table_offset(addr); i < L1_PAGETABLE_ENTRIES && extra->smfn < extra->emfn;
@@ -1681,6 +1692,10 @@ void __init efi_init_memory(void) extra_head = extra->next;xfree (extra); } + +UNMAP_XEN_PAGETABLE_NEW (l1t); +UNMAP_XEN_PAGETABLE_NEW (pl2e); +UNMAP_XEN_PAGETABLE_NEW (pl3e); }/* Insert Xen mappings. */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 32/84 efi: add emacs block to boot.c
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/common/efi/boot.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
xen/common/efi/boot.c +10 -0
@@ -1705,3 +1705,13 @@ void __init efi_init_memory(void) #endif }#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 33/84 efi: switch EFI L4 table to use new APIs
In reply to [email protected]From: Wei Liu <[email protected]>
This requires storing the MFN instead of linear address of the L4 table. Adjust code accordingly.
--- xen/arch/x86/efi/runtime.h | 12 +++++++++--- xen/common/efi/boot.c | 8 ++++++-- xen/common/efi/efi.h | 3 ++- xen/common/efi/runtime.c | 8 ++++---- 4 files changed, 21 insertions(+), 10 deletions(-)
xen/arch/x86/efi/runtime.h +9 -3
@@ -2,11 +2,17 @@#include <asm/mc146818rtc.h> #ifndef COMPAT -l4_pgentry_t *__read_mostly efi_l4_pgtable; +mfn_t __read_mostly efi_l4_mfn =INVALID_MFN_INITIALIZER ;void efi_update_l4_pgtable (unsigned int l4idx,l4_pgentry_t l4e) { -if ( efi_l4_pgtable ) -l4e_write (efi_l4_pgtable + l4idx, l4e); +if ( !mfn_eq (efi_l4_mfn,INVALID_MFN ) ) + { +l4_pgentry_t *l4t; + + l4t =map_xen_pagetable_new (efi_l4_mfn); +l4e_write (l4t + l4idx, l4e); +UNMAP_XEN_PAGETABLE_NEW (l4t); + } }#endif
xen/common/efi/boot.c +6 -2
@@ -1488,6 +1488,7 @@ void __init efi_init_memory(void) unsigned int prot; } *extra, *extra_head =NULL ;#endif +l4_pgentry_t *efi_l4_pgtable;free_ebmalloc_unused_mem ();
@@ -1603,8 +1604,9 @@ void __init efi_init_memory(void) mdesc_ver, efi_memmap);#else /* Set up 1:1 page tables to do runtime calls in "physical" mode. */ - efi_l4_pgtable =alloc_xen_pagetable (); -BUG_ON (!efi_l4_pgtable); + efi_l4_mfn =alloc_xen_pagetable_new (); +BUG_ON (mfn_eq (efi_l4_mfn,INVALID_MFN )); + efi_l4_pgtable =map_xen_pagetable_new (efi_l4_mfn);clear_page (efi_l4_pgtable);copy_mapping (efi_l4_pgtable,0 , max_page, ram_range_valid);
@@ -1703,6 +1705,8 @@ void __init efi_init_memory(void) i < l4_table_offset(DIRECTMAP_VIRT_END); ++i ) efi_l4_pgtable[i] = idle_pg_table[i];#endif + + UNMAP_XEN_PAGETABLE_NEW(efi_l4_pgtable); }#endif
xen/common/efi/efi.h +2 -1
@@ -6,6 +6,7 @@#include <efi/eficapsule.h> #include <efi/efiapi.h> #include <xen/efi.h> +#include <xen/mm.h> #include <xen/spinlock.h> #include <asm/page.h>
@@ -29,7 +30,7 @@ extern UINTN efi_memmap_size, efi_mdesc_size;extern void *efi_memmap;#ifdef CONFIG_X86 -extern l4_pgentry_t *efi_l4_pgtable; +extern mfn_t efi_l4_mfn;#endif extern const struct efi_pci_rom *efi_pci_roms;
xen/common/efi/runtime.c +4 -4
@@ -85,7 +85,7 @@ struct efi_rs_state efi_rs_enter(void)static const u32 mxcsr =MXCSR_DEFAULT ;struct efi_rs_state state = { .cr3 =0 }; -if ( !efi_l4_pgtable ) +if (mfn_eq (efi_l4_mfn,INVALID_MFN ) )return state; state.cr3 =read_cr3 ();
@@ -111,7 +111,7 @@ struct efi_rs_state efi_rs_enter(void)lgdt (&gdt_desc); } -switch_cr3_cr4 (virt_to_maddr (efi_l4_pgtable),read_cr4 ()); +switch_cr3_cr4 (mfn_to_maddr (efi_l4_mfn),read_cr4 ());return state; }
@@ -140,9 +140,9 @@ void efi_rs_leave(struct efi_rs_state *state)bool efi_rs_using_pgtables (void ) { -return efi_l4_pgtable && +return !mfn_eq (efi_l4_mfn,INVALID_MFN ) && (smp_processor_id () == efi_rs_on_cpu) && - (read_cr3 () ==virt_to_maddr (efi_l4_pgtable)); + (read_cr3 () ==mfn_to_maddr (efi_l4_mfn)); }unsigned long efi_get_time (void )
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 34/84 x86/smpboot: add emacs block
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/smpboot.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
xen/arch/x86/smpboot.c +10 -0
@@ -1380,3 +1380,13 @@ void __init smp_intr_init(void)set_direct_apic_vector (INVALIDATE_TLB_VECTOR , invalidate_interrupt);set_direct_apic_vector (CALL_FUNCTION_VECTOR , call_function_interrupt); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 35/84 x86/smpboot: clone_mapping should have one exit path
In reply to [email protected]From: Wei Liu <[email protected]>
We will soon need to clean up page table mappings in the exit path.
No functional change.
--- xen/arch/x86/smpboot.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
xen/arch/x86/smpboot.c +28 -7
@@ -669,6 +669,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)l3_pgentry_t *pl3e;l2_pgentry_t *pl2e;l1_pgentry_t *pl1e; +int rc;/* * Sanity check 'linear'. We only allow cloning from the Xen virtual
@@ -676,11 +677,17 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)*/ if (root_table_offset (linear) >ROOT_PAGETABLE_LAST_XEN_SLOT ||root_table_offset (linear) <ROOT_PAGETABLE_FIRST_XEN_SLOT ) -return -EINVAL ; + { + rc = -EINVAL ; + goto out; + }if ( linear <XEN_VIRT_START || (linear >=XEN_VIRT_END && linear <DIRECTMAP_VIRT_START ) ) -return -EINVAL ; + { + rc = -EINVAL ; + goto out; + } pl3e =l4e_to_l3e (idle_pg_table[root_table_offset (linear)]) +l3_table_offset (linear);
@@ -709,7 +716,10 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (linear); flags =l1e_get_flags (*pl1e);if ( !(flags & _PAGE_PRESENT) ) -return 0 ; + { + rc =0 ; + goto out; + } pfn =l1e_get_pfn (*pl1e); } }
@@ -718,7 +728,10 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) { pl3e =alloc_xen_pagetable ();if ( !pl3e ) -return -ENOMEM ; + { + rc = -ENOMEM ; + goto out; + }clear_page (pl3e);l4e_write (&rpt[root_table_offset (linear)],l4e_from_paddr (__pa (pl3e), __PAGE_HYPERVISOR));
@@ -732,7 +745,10 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) { pl2e =alloc_xen_pagetable ();if ( !pl2e ) -return -ENOMEM ; + { + rc = -ENOMEM ; + goto out; + }clear_page (pl2e);l3e_write (pl3e,l3e_from_paddr (__pa (pl2e), __PAGE_HYPERVISOR)); }
@@ -748,7 +764,10 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) { pl1e =alloc_xen_pagetable ();if ( !pl1e ) -return -ENOMEM ; + { + rc = -ENOMEM ; + goto out; + }clear_page (pl1e);l2e_write (pl2e,l2e_from_paddr (__pa (pl1e), __PAGE_HYPERVISOR)); }
@@ -769,7 +788,9 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)else l1e_write (pl1e,l1e_from_pfn (pfn, flags)); -return 0 ; + rc =0 ; + out: +return rc; } DEFINE_PER_CPU(root_pgentry_t *, root_pgt);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 36/84 x86/smpboot: switch pl3e to use new APIs in clone_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/smpboot.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
xen/arch/x86/smpboot.c +15 -7
@@ -666,7 +666,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) {unsigned long linear = (unsigned long )ptr, pfn;unsigned int flags; -l3_pgentry_t *pl3e; +l3_pgentry_t *pl3e =NULL ;l2_pgentry_t *pl2e;l1_pgentry_t *pl1e;int rc;
@@ -689,8 +689,9 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) goto out; } - pl3e =l4e_to_l3e (idle_pg_table[root_table_offset (linear)]) + -l3_table_offset (linear); + pl3e =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[root_table_offset (linear)])); + pl3e +=l3_table_offset (linear); flags =l3e_get_flags (*pl3e);ASSERT (flags & _PAGE_PRESENT);
@@ -724,20 +725,26 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) } } +UNMAP_XEN_PAGETABLE_NEW (pl3e); +if ( !(root_get_flags (rpt[root_table_offset (linear)]) & _PAGE_PRESENT) ) { - pl3e =alloc_xen_pagetable (); -if ( !pl3e ) +mfn_t l3t_mfn =alloc_xen_pagetable_new (); + +if (mfn_eq (l3t_mfn,INVALID_MFN ) ) { rc = -ENOMEM ; goto out; } + + pl3e =map_xen_pagetable_new (l3t_mfn);clear_page (pl3e);l4e_write (&rpt[root_table_offset (linear)], -l4e_from_paddr (__pa (pl3e), __PAGE_HYPERVISOR)); +l4e_from_mfn (l3t_mfn, __PAGE_HYPERVISOR)); }else - pl3e =l4e_to_l3e (rpt[root_table_offset (linear)]); + pl3e =map_xen_pagetable_new ( +l4e_get_mfn (rpt[root_table_offset (linear)])); pl3e +=l3_table_offset (linear);
@@ -790,6 +797,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 37/84 x86/smpboot: switch pl2e to use new APIs in clone_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/smpboot.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +12 -6
@@ -667,7 +667,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)unsigned long linear = (unsigned long )ptr, pfn;unsigned int flags;l3_pgentry_t *pl3e =NULL ; -l2_pgentry_t *pl2e; +l2_pgentry_t *pl2e =NULL ;l1_pgentry_t *pl1e;int rc;
@@ -703,7 +703,8 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) }else { - pl2e =l3e_to_l2e (*pl3e) +l2_table_offset (linear); + pl2e =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + pl2e +=l2_table_offset (linear); flags =l2e_get_flags (*pl2e);ASSERT (flags & _PAGE_PRESENT);if ( flags & _PAGE_PSE )
@@ -725,6 +726,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) } } +UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e);if ( !(root_get_flags (rpt[root_table_offset (linear)]) & _PAGE_PRESENT) )
@@ -750,19 +752,22 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) { - pl2e =alloc_xen_pagetable (); -if ( !pl2e ) +mfn_t l2t_mfn =alloc_xen_pagetable_new (); + +if (mfn_eq (l2t_mfn,INVALID_MFN ) ) { rc = -ENOMEM ; goto out; } + + pl2e =map_xen_pagetable_new (l2t_mfn);clear_page (pl2e); -l3e_write (pl3e,l3e_from_paddr (__pa (pl2e), __PAGE_HYPERVISOR)); +l3e_write (pl3e,l3e_from_mfn (l2t_mfn, __PAGE_HYPERVISOR)); }else {ASSERT (!(l3e_get_flags (*pl3e) & _PAGE_PSE)); - pl2e =l3e_to_l2e (*pl3e); + pl2e =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); } pl2e +=l2_table_offset (linear);
@@ -797,6 +802,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 38/84 x86/smpboot: switch pl1e to use new APIs in clone_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/smpboot.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +12 -6
@@ -668,7 +668,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)unsigned int flags;l3_pgentry_t *pl3e =NULL ;l2_pgentry_t *pl2e =NULL ; -l1_pgentry_t *pl1e; +l1_pgentry_t *pl1e =NULL ;int rc;/*
@@ -715,7 +715,8 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) }else { - pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (linear); + pl1e =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); + pl1e +=l1_table_offset (linear); flags =l1e_get_flags (*pl1e);if ( !(flags & _PAGE_PRESENT) ) {
@@ -726,6 +727,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) } } +UNMAP_XEN_PAGETABLE_NEW (pl1e);UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e);
@@ -774,19 +776,22 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) { - pl1e =alloc_xen_pagetable (); -if ( !pl1e ) +mfn_t l1t_mfn =alloc_xen_pagetable_new (); + +if (mfn_eq (l1t_mfn,INVALID_MFN ) ) { rc = -ENOMEM ; goto out; } + + pl1e =map_xen_pagetable_new (l1t_mfn);clear_page (pl1e); -l2e_write (pl2e,l2e_from_paddr (__pa (pl1e), __PAGE_HYPERVISOR)); +l2e_write (pl2e,l2e_from_mfn (l1t_mfn, __PAGE_HYPERVISOR)); }else {ASSERT (!(l2e_get_flags (*pl2e) & _PAGE_PSE)); - pl1e =l2e_to_l1e (*pl2e); + pl1e =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); } pl1e +=l1_table_offset (linear);
@@ -802,6 +807,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) rc =0 ; out: +UNMAP_XEN_PAGETABLE_NEW (pl1e);UNMAP_XEN_PAGETABLE_NEW (pl2e);UNMAP_XEN_PAGETABLE_NEW (pl3e);return rc;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 39/84 x86/smpboot: drop lXe_to_lYe invocations from cleanup_cpu_root_pgt
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/smpboot.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
xen/arch/x86/smpboot.c +11 -5
@@ -893,23 +893,27 @@ static void cleanup_cpu_root_pgt(unsigned int cpu) r < root_table_offset(HYPERVISOR_VIRT_END); ++r ) {l3_pgentry_t *l3t; +mfn_t l3t_mfn;unsigned int i3;if ( !(root_get_flags (rpt[r]) & _PAGE_PRESENT) )continue ; - l3t =l4e_to_l3e (rpt[r]); + l3t_mfn =l4e_get_mfn (rpt[r]); + l3t =map_xen_pagetable_new (l3t_mfn);for ( i3 =0 ; i3 <L3_PAGETABLE_ENTRIES ; ++i3 ) {l2_pgentry_t *l2t; +mfn_t l2t_mfn;unsigned int i2;if ( !(l3e_get_flags (l3t[i3]) & _PAGE_PRESENT) )continue ;ASSERT (!(l3e_get_flags (l3t[i3]) & _PAGE_PSE)); - l2t =l3e_to_l2e (l3t[i3]); + l2t_mfn =l3e_get_mfn (l3t[i3]); + l2t =map_xen_pagetable_new (l2t_mfn);for ( i2 =0 ; i2 <L2_PAGETABLE_ENTRIES ; ++i2 ) {
@@ -917,13 +921,15 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)continue ;ASSERT (!(l2e_get_flags (l2t[i2]) & _PAGE_PSE)); -free_xen_pagetable (l2e_to_l1e (l2t[i2])); +free_xen_pagetable_new (l2e_get_mfn (l2t[i2])); } -free_xen_pagetable (l2t); +UNMAP_XEN_PAGETABLE_NEW (l2t); +free_xen_pagetable_new (l2t_mfn); } -free_xen_pagetable (l3t); +UNMAP_XEN_PAGETABLE_NEW (l3t); +free_xen_pagetable_new (l3t_mfn); }free_xen_pagetable (rpt);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 40/84 x86: switch root_pgt to mfn_t and use new APIs
In reply to [email protected]From: Wei Liu <[email protected]>
This then requires moving declaration of root page table mfn into mm.h and modify setup_cpu_root_pgt to have a single exit path.
We also need to force map_domain_page to use direct map when switching per-domain mappings. This is contrary to our end goal of removing direct map, but this will be removed once we make map_domain_page context-switch safe in another (large) patch series.
--- xen/arch/x86/domain.c | 15 ++++++++++--- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/pv/domain.c | 2 +- xen/arch/x86/smpboot.c | 40 ++++++++++++++++++++++----------- xen/include/asm-x86/mm.h | 2 ++ xen/include/asm-x86/processor.h | 2 +- 7 files changed, 45 insertions(+), 20 deletions(-)
xen/arch/x86/domain.c +12 -3
@@ -69,6 +69,7 @@#include <asm/pv/domain.h> #include <asm/pv/mm.h> #include <asm/spec_ctrl.h> +#include <asm/setup.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
@@ -1580,12 +1581,20 @@ void paravirt_ctxt_switch_from(struct vcpu *v)void paravirt_ctxt_switch_to (struct vcpu *v) { -root_pgentry_t *root_pgt =this_cpu (root_pgt); +mfn_t rpt_mfn =this_cpu (root_pgt_mfn); -if ( root_pgt ) - root_pgt[root_table_offset (PERDOMAIN_VIRT_START )] = +if ( !mfn_eq (rpt_mfn,INVALID_MFN ) ) + { +root_pgentry_t *rpt; + +mapcache_override_current (INVALID_VCPU ); + rpt =map_xen_pagetable_new (rpt_mfn); + rpt[root_table_offset (PERDOMAIN_VIRT_START )] =l4e_from_page (v->domain->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW); +UNMAP_XEN_PAGETABLE_NEW (rpt); +mapcache_override_current (NULL ); + }if (unlikely (v->arch.dr7 &DR7_ACTIVE_MASK ) )activate_debugregs (v);
xen/arch/x86/domain_page.c +1 -1
@@ -57,7 +57,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)return v; } -void __init mapcache_override_current (struct vcpu *v) +void mapcache_override_current (struct vcpu *v) {this_cpu (override) = v; }
xen/arch/x86/mm.c +1 -1
@@ -530,7 +530,7 @@ void write_ptbase(struct vcpu *v)if (is_pv_vcpu (v) && v->domain->arch.pv.xpti ) { cpu_info->root_pgt_changed = true; - cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)); + cpu_info->pv_cr3 =mfn_to_maddr (this_cpu (root_pgt_mfn));if ( new_cr4 &X86_CR4_PCIDE ) cpu_info->pv_cr3 |=get_pcid_bits (v, true);switch_cr3_cr4 (v->arch.cr3, new_cr4);
xen/arch/x86/pv/domain.c +1 -1
@@ -360,7 +360,7 @@ static void _toggle_guest_pt(struct vcpu *v)if ( d->arch.pv.xpti ) { cpu_info->root_pgt_changed = true; - cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)) | + cpu_info->pv_cr3 =mfn_to_maddr (this_cpu (root_pgt_mfn)) | (d->arch.pv.pcid ?get_pcid_bits (v, true) :0 ); }
xen/arch/x86/smpboot.c +27 -13
@@ -813,7 +813,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)return rc; } -DEFINE_PER_CPU(root_pgentry_t *, root_pgt); +DEFINE_PER_CPU (mfn_t, root_pgt_mfn);static root_pgentry_t common_pgt;
@@ -821,19 +821,27 @@ extern const char _stextentry[], _etextentry[];static int setup_cpu_root_pgt (unsigned int cpu) { -root_pgentry_t *rpt; +root_pgentry_t *rpt =NULL ; +mfn_t rpt_mfn;unsigned int off;int rc;if ( !opt_xpti_hwdom && !opt_xpti_domu ) -return 0 ; + { + rc =0 ; + goto out; + } - rpt =alloc_xen_pagetable (); -if ( !rpt ) -return -ENOMEM ; + rpt_mfn =alloc_xen_pagetable_new (); +if (mfn_eq (rpt_mfn,INVALID_MFN ) ) + { + rc = -ENOMEM ; + goto out; + } + rpt =map_xen_pagetable_new (rpt_mfn);clear_page (rpt); -per_cpu (root_pgt, cpu) = rpt; +per_cpu (root_pgt_mfn, cpu) = rpt_mfn; rpt[root_table_offset (RO_MPT_VIRT_START )] = idle_pg_table[root_table_offset (RO_MPT_VIRT_START )];
@@ -850,7 +858,7 @@ static int setup_cpu_root_pgt(unsigned int cpu) rc =clone_mapping (ptr, rpt);if ( rc ) -return rc; + goto out; common_pgt = rpt[root_table_offset (XEN_VIRT_START )]; }
@@ -875,19 +883,24 @@ static int setup_cpu_root_pgt(unsigned int cpu)if ( !rc ) rc =clone_mapping ((void *)per_cpu (stubs.addr, cpu), rpt); + out: +UNMAP_XEN_PAGETABLE_NEW (rpt);return rc; }static void cleanup_cpu_root_pgt (unsigned int cpu) { -root_pgentry_t *rpt =per_cpu (root_pgt, cpu); +mfn_t rpt_mfn =per_cpu (root_pgt_mfn, cpu); +root_pgentry_t *rpt;unsigned int r;unsigned long stub_linear =per_cpu (stubs.addr, cpu); -if ( !rpt ) +if (mfn_eq (rpt_mfn,INVALID_MFN ) )return ; -per_cpu (root_pgt, cpu) =NULL ; +per_cpu (root_pgt_mfn, cpu) =INVALID_MFN ; + + rpt =map_xen_pagetable_new (rpt_mfn);for ( r =root_table_offset (DIRECTMAP_VIRT_START ); r <root_table_offset (HYPERVISOR_VIRT_END ); ++r )
@@ -932,7 +945,8 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)free_xen_pagetable_new (l3t_mfn); } -free_xen_pagetable (rpt); +UNMAP_XEN_PAGETABLE_NEW (rpt); +free_xen_pagetable_new (rpt_mfn);/* Also zap the stub mapping for this CPU. */ if ( stub_linear )
@@ -1136,7 +1150,7 @@ void __init smp_prepare_cpus(void) rc =setup_cpu_root_pgt (0 );if ( rc )panic ("Error %d setting up PV root page table\n" , rc); -if (per_cpu (root_pgt,0 ) ) +if ( !mfn_eq (per_cpu (root_pgt_mfn,0 ),INVALID_MFN ) ) {get_cpu_info ()->pv_cr3 =0 ;
xen/include/asm-x86/mm.h +2 -0
@@ -646,4 +646,6 @@ void free_xen_pagetable_new(mfn_t mfn);l1_pgentry_t *virt_to_xen_l1e (unsigned long v); +DECLARE_PER_CPU (mfn_t, root_pgt_mfn); +#endif /* __ASM_X86_MM_H__ */
xen/include/asm-x86/processor.h +1 -1
@@ -465,7 +465,7 @@ static inline void disable_each_ist(idt_entry_t *idt)extern idt_entry_t idt_table[];extern idt_entry_t *idt_tables[]; -DECLARE_PER_CPU(root_pgentry_t *, root_pgt); +DECLARE_PER_CPU(struct tss_struct, init_tss);extern void write_ptbase (struct vcpu *v);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 41/84 x86/shim: map and unmap page tables in replace_va_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/pv/shim.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
xen/arch/x86/pv/shim.c +15 -5
@@ -167,15 +167,25 @@ static void __init replace_va_mapping(struct domain *d, l4_pgentry_t *l4start, unsigned long va, mfn_t mfn) {l4_pgentry_t *pl4e = l4start +l4_table_offset (va); -l3_pgentry_t *pl3e =l4e_to_l3e (*pl4e) +l3_table_offset (va); -l2_pgentry_t *pl2e =l3e_to_l2e (*pl3e) +l2_table_offset (va); -l1_pgentry_t *pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (va); -struct page_info *page =mfn_to_page (l1e_get_mfn (*pl1e)); +l3_pgentry_t *pl3e; +l2_pgentry_t *pl2e; +l1_pgentry_t *pl1e; -put_page_and_type (page); + pl3e =map_xen_pagetable_new (l4e_get_mfn (*pl4e)); + pl3e +=l3_table_offset (va); + pl2e =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + pl2e +=l2_table_offset (va); + pl1e =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); + pl1e +=l1_table_offset (va); + +put_page_and_type (mfn_to_page (l1e_get_mfn (*pl1e))); *pl1e =l1e_from_mfn (mfn, (!is_pv_32bit_domain (d) ?L1_PROT :COMPAT_L1_PROT )); + +UNMAP_XEN_PAGETABLE_NEW (pl1e); +UNMAP_XEN_PAGETABLE_NEW (pl2e); +UNMAP_XEN_PAGETABLE_NEW (pl3e); }static void evtchn_reserve (struct domain *d,unsigned int port)
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 42/84 x86_64/mm: map and unmap page tables in m2p_mapped
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
xen/arch/x86/x86_64/mm.c +15 -7
@@ -130,28 +130,36 @@ static int m2p_mapped(unsigned long spfn) {unsigned long va;l3_pgentry_t *l3_ro_mpt; -l2_pgentry_t *l2_ro_mpt; +l2_pgentry_t *l2_ro_mpt =NULL ; +int rc =M2P_NO_MAPPED ; va =RO_MPT_VIRT_START + spfn *sizeof (*machine_to_phys_mapping); - l3_ro_mpt =l4e_to_l3e (idle_pg_table[l4_table_offset (va)]); + l3_ro_mpt =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (va)]));switch (l3e_get_flags (l3_ro_mpt[l3_table_offset (va)]) & (_PAGE_PRESENT |_PAGE_PSE)) {case _PAGE_PSE|_PAGE_PRESENT: -return M2P_1G_MAPPED ; + rc =M2P_1G_MAPPED ; + goto out;/* Check for next level */ case _PAGE_PRESENT:break ;default : -return M2P_NO_MAPPED ; + rc =M2P_NO_MAPPED ; + goto out; } - l2_ro_mpt =l3e_to_l2e (l3_ro_mpt[l3_table_offset (va)]); + l2_ro_mpt =map_xen_pagetable_new ( +l3e_get_mfn (l3_ro_mpt[l3_table_offset (va)]));if (l2e_get_flags (l2_ro_mpt[l2_table_offset (va)]) & _PAGE_PRESENT) -return M2P_2M_MAPPED ; + rc =M2P_2M_MAPPED ; -return M2P_NO_MAPPED ; + out: +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); +UNMAP_XEN_PAGETABLE_NEW (l3_ro_mpt); +return rc; }static int share_hotadd_m2p_table (struct mem_hotadd_info *info)
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 43/84 x86_64/mm: map and unmap page tables in share_hotadd_m2p_table
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
xen/arch/x86/x86_64/mm.c +23 -8
@@ -166,8 +166,8 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info) {unsigned long i, n, v;mfn_t m2p_start_mfn =INVALID_MFN ; -l3_pgentry_t l3e; -l2_pgentry_t l2e; +l3_pgentry_t l3e, *l3t; +l2_pgentry_t l2e, *l2t;/* M2P table is mappable read-only by privileged domains. */ for ( v = RDWR_MPT_VIRT_START;
@@ -175,14 +175,22 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info) v += n << PAGE_SHIFT ) { n =L2_PAGETABLE_ENTRIES *L1_PAGETABLE_ENTRIES ; - l3e =l4e_to_l3e (idle_pg_table[l4_table_offset (v)])[ -l3_table_offset (v)]; + + l3t =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (v)])); + l3e = l3t[l3_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l3t); +if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) )continue ;if ( !(l3e_get_flags (l3e) & _PAGE_PSE) ) { n =L1_PAGETABLE_ENTRIES ; - l2e =l3e_to_l2e (l3e)[l2_table_offset (v)]; + + l2t =map_xen_pagetable_new (l3e_get_mfn (l3e)); + l2e = l2t[l2_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l2t); +if ( !(l2e_get_flags (l2e) & _PAGE_PRESENT) )continue ; m2p_start_mfn =l2e_get_mfn (l2e);
@@ -203,11 +211,18 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info) v !=RDWR_COMPAT_MPT_VIRT_END ; v += 1 << L2_PAGETABLE_SHIFT ) { - l3e =l4e_to_l3e (idle_pg_table[l4_table_offset (v)])[ -l3_table_offset (v)]; + l3t =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (v)])); + l3e = l3t[l3_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l3t); +if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) )continue ; - l2e =l3e_to_l2e (l3e)[l2_table_offset (v)]; + + l2t =map_xen_pagetable_new (l3e_get_mfn (l3e)); + l2e = l2t[l2_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l2t); +if ( !(l2e_get_flags (l2e) & _PAGE_PRESENT) )continue ; m2p_start_mfn =l2e_get_mfn (l2e);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 44/84 x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/x86_64/mm.c +7 -2
@@ -252,11 +252,13 @@ static void destroy_compat_m2p_mapping(struct mem_hotadd_info *info)if ( emap > ((RDWR_COMPAT_MPT_VIRT_END -RDWR_COMPAT_MPT_VIRT_START ) >>2 ) ) emap = (RDWR_COMPAT_MPT_VIRT_END -RDWR_COMPAT_MPT_VIRT_START ) >>2 ; - l3_ro_mpt =l4e_to_l3e (idle_pg_table[l4_table_offset (HIRO_COMPAT_MPT_VIRT_START )]); + l3_ro_mpt =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (HIRO_COMPAT_MPT_VIRT_START )]));ASSERT (l3e_get_flags (l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )]) & _PAGE_PRESENT); - l2_ro_mpt =l3e_to_l2e (l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )]); + l2_ro_mpt =map_xen_pagetable_new ( +l3e_get_mfn (l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )]));for ( i = smap; i < emap; ) {
@@ -278,6 +280,9 @@ static void destroy_compat_m2p_mapping(struct mem_hotadd_info *info) i +=1UL << (L2_PAGETABLE_SHIFT -2 ); } +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); +UNMAP_XEN_PAGETABLE_NEW (l3_ro_mpt); +return ; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 45/84 x86_64/mm: map and unmap page tables in destroy_m2p_mapping
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
xen/arch/x86/x86_64/mm.c +14 -4
@@ -292,7 +292,8 @@ static void destroy_m2p_mapping(struct mem_hotadd_info *info)unsigned long i, va, rwva;unsigned long smap = info->spfn, emap = info->epfn; - l3_ro_mpt =l4e_to_l3e (idle_pg_table[l4_table_offset (RO_MPT_VIRT_START )]); + l3_ro_mpt =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (RO_MPT_VIRT_START )]));/* * No need to clean m2p structure existing before the hotplug
@@ -314,26 +315,35 @@ static void destroy_m2p_mapping(struct mem_hotadd_info *info)continue ; } - l2_ro_mpt =l3e_to_l2e (l3_ro_mpt[l3_table_offset (va)]); + l2_ro_mpt =map_xen_pagetable_new ( +l3e_get_mfn (l3_ro_mpt[l3_table_offset (va)]));if (!(l2e_get_flags (l2_ro_mpt[l2_table_offset (va)]) & _PAGE_PRESENT)) { i = ( i & ~((1UL << (L2_PAGETABLE_SHIFT -3 )) -1 )) + (1UL << (L2_PAGETABLE_SHIFT -3 )) ; +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt);continue ; } pt_pfn =l2e_get_pfn (l2_ro_mpt[l2_table_offset (va)]);if (hotadd_mem_valid (pt_pfn, info) ) { +l2_pgentry_t *l2t; +destroy_xen_mappings (rwva, rwva + (1UL <<L2_PAGETABLE_SHIFT )); - l2_ro_mpt =l3e_to_l2e (l3_ro_mpt[l3_table_offset (va)]); -l2e_write (&l2_ro_mpt[l2_table_offset (va)],l2e_empty ()); + l2t =map_xen_pagetable_new ( +l3e_get_mfn (l3_ro_mpt[l3_table_offset (va)])); +l2e_write (&l2t[l2_table_offset (va)],l2e_empty ()); +UNMAP_XEN_PAGETABLE_NEW (l2t); } i = ( i & ~((1UL << (L2_PAGETABLE_SHIFT -3 )) -1 )) + (1UL << (L2_PAGETABLE_SHIFT -3 )); +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); } +UNMAP_XEN_PAGETABLE_NEW (l3_ro_mpt); +destroy_compat_m2p_mapping (info);/* Brute-Force flush all TLB */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 46/84 x86_64/mm: map and unmap page tables in setup_compat_m2p_table
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/x86_64/mm.c +7 -2
@@ -382,11 +382,13 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info) va =HIRO_COMPAT_MPT_VIRT_START + smap *sizeof (*compat_machine_to_phys_mapping); - l3_ro_mpt =l4e_to_l3e (idle_pg_table[l4_table_offset (va)]); + l3_ro_mpt =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (va)]));ASSERT (l3e_get_flags (l3_ro_mpt[l3_table_offset (va)]) & _PAGE_PRESENT); - l2_ro_mpt =l3e_to_l2e (l3_ro_mpt[l3_table_offset (va)]); + l2_ro_mpt =map_xen_pagetable_new ( +l3e_get_mfn (l3_ro_mpt[l3_table_offset (va)]));#define MFN (x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int))#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \
@@ -424,6 +426,9 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info) }#undef CNT#undef MFN + +UNMAP_XEN_PAGETABLE_NEW (l2_ro_mpt); +UNMAP_XEN_PAGETABLE_NEW (l3_ro_mpt);return err; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 47/84 x86_64/mm: map and unmap page tables in cleanup_frame_table
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
xen/arch/x86/x86_64/mm.c +17 -7
@@ -801,8 +801,8 @@ void free_compat_arg_xlat(struct vcpu *v)static void cleanup_frame_table (struct mem_hotadd_info *info) {unsigned long sva, eva; -l3_pgentry_t l3e; -l2_pgentry_t l2e; +l3_pgentry_t l3e, *l3t; +l2_pgentry_t l2e, *l2t;mfn_t spfn, epfn; spfn =_mfn (info->spfn);
@@ -816,8 +816,10 @@ static void cleanup_frame_table(struct mem_hotadd_info *info)while (sva < eva) { - l3e =l4e_to_l3e (idle_pg_table[l4_table_offset (sva)])[ -l3_table_offset (sva)]; + l3t =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (sva)])); + l3e = l3t[l3_table_offset (sva)]; +UNMAP_XEN_PAGETABLE_NEW (l3t);if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) || (l3e_get_flags (l3e) & _PAGE_PSE) ) {
@@ -826,7 +828,9 @@ static void cleanup_frame_table(struct mem_hotadd_info *info)continue ; } - l2e =l3e_to_l2e (l3e)[l2_table_offset (sva)]; + l2t =map_xen_pagetable_new (l3e_get_mfn (l3e)); + l2e = l2t[l2_table_offset (sva)]; +UNMAP_XEN_PAGETABLE_NEW (l2t);ASSERT (l2e_get_flags (l2e) & _PAGE_PRESENT); if ( (l2e_get_flags(l2e) & (_PAGE_PRESENT | _PAGE_PSE)) ==
@@ -842,8 +846,14 @@ static void cleanup_frame_table(struct mem_hotadd_info *info)continue ; } -ASSERT (l1e_get_flags (l2e_to_l1e (l2e)[l1_table_offset (sva)]) & - _PAGE_PRESENT); +#ifndef NDEBUG + { +l1_pgentry_t *l1t =map_xen_pagetable_new (l2e_get_mfn (l2e)); +ASSERT (l1e_get_flags (l1t[l1_table_offset (sva)]) & + _PAGE_PRESENT); +UNMAP_XEN_PAGETABLE_NEW (l1t); + } +#endif sva = (sva & ~((1UL <<PAGE_SHIFT ) -1 )) + (1UL <<PAGE_SHIFT ); }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 48/84 x86_64/mm: map and unmap page tables in subarch_init_memory
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
xen/arch/x86/x86_64/mm.c +23 -8
@@ -930,8 +930,8 @@ static int extend_frame_table(struct mem_hotadd_info *info)void __init subarch_init_memory (void ) {unsigned long i, n, v, m2p_start_mfn; -l3_pgentry_t l3e; -l2_pgentry_t l2e; +l3_pgentry_t l3e, *l3t; +l2_pgentry_t l2e, *l2t;BUILD_BUG_ON (RDWR_MPT_VIRT_START & ((1UL <<L3_PAGETABLE_SHIFT ) -1 ));BUILD_BUG_ON (RDWR_MPT_VIRT_END & ((1UL <<L3_PAGETABLE_SHIFT ) -1 ));
@@ -941,14 +941,22 @@ void __init subarch_init_memory(void) v += n << PAGE_SHIFT ) { n =L2_PAGETABLE_ENTRIES *L1_PAGETABLE_ENTRIES ; - l3e =l4e_to_l3e (idle_pg_table[l4_table_offset (v)])[ -l3_table_offset (v)]; + + l3t =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (v)])); + l3e = l3t[l3_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l3t); +if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) )continue ;if ( !(l3e_get_flags (l3e) & _PAGE_PSE) ) { n =L1_PAGETABLE_ENTRIES ; - l2e =l3e_to_l2e (l3e)[l2_table_offset (v)]; + + l2t =map_xen_pagetable_new (l3e_get_mfn (l3e)); + l2e = l2t[l2_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l2t); +if ( !(l2e_get_flags (l2e) & _PAGE_PRESENT) )continue ; m2p_start_mfn =l2e_get_pfn (l2e);
@@ -967,11 +975,18 @@ void __init subarch_init_memory(void) v !=RDWR_COMPAT_MPT_VIRT_END ; v += 1 << L2_PAGETABLE_SHIFT ) { - l3e =l4e_to_l3e (idle_pg_table[l4_table_offset (v)])[ -l3_table_offset (v)]; + l3t =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (v)])); + l3e = l3t[l3_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l3t); +if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) )continue ; - l2e =l3e_to_l2e (l3e)[l2_table_offset (v)]; + + l2t =map_xen_pagetable_new (l3e_get_mfn (l3e)); + l2e = l2t[l2_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l2t); +if ( !(l2e_get_flags (l2e) & _PAGE_PRESENT) )continue ; m2p_start_mfn =l2e_get_pfn (l2e);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 49/84 x86_64/mm: map and unmap page tables in subarch_memory_op
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/x86_64/mm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
xen/arch/x86/x86_64/mm.c +10 -5
@@ -1016,8 +1016,8 @@ void __init subarch_init_memory(void)long subarch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct xen_machphys_mfn_list xmml; -l3_pgentry_t l3e; -l2_pgentry_t l2e; +l3_pgentry_t l3e, *l3t; +l2_pgentry_t l2e, *l2t;unsigned long v, limit;xen_pfn_t mfn, last_mfn;unsigned int i;
@@ -1036,13 +1036,18 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) (v < (unsigned long )(machine_to_phys_mapping + max_page)); i++, v += 1UL << L2_PAGETABLE_SHIFT ) { - l3e =l4e_to_l3e (idle_pg_table[l4_table_offset (v)])[ -l3_table_offset (v)]; + l3t =map_xen_pagetable_new ( +l4e_get_mfn (idle_pg_table[l4_table_offset (v)])); + l3e = l3t[l3_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l3t); +if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) ) mfn = last_mfn;else if ( !(l3e_get_flags (l3e) & _PAGE_PSE) ) { - l2e =l3e_to_l2e (l3e)[l2_table_offset (v)]; + l2t =map_xen_pagetable_new (l3e_get_mfn (l3e)); + l2e = l2t[l2_table_offset (v)]; +UNMAP_XEN_PAGETABLE_NEW (l2t);if (l2e_get_flags (l2e) & _PAGE_PRESENT ) mfn =l2e_get_pfn (l2e);else
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 50/84 x86/smpboot: remove lXe_to_lYe in cleanup_cpu_root_pgt
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/smpboot.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
xen/arch/x86/smpboot.c +9 -3
@@ -951,11 +951,17 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)/* Also zap the stub mapping for this CPU. */ if ( stub_linear ) { -l3_pgentry_t *l3t =l4e_to_l3e (common_pgt); -l2_pgentry_t *l2t =l3e_to_l2e (l3t[l3_table_offset (stub_linear)]); -l1_pgentry_t *l1t =l2e_to_l1e (l2t[l2_table_offset (stub_linear)]); +l3_pgentry_t *l3t =map_xen_pagetable_new (l4e_get_mfn (common_pgt)); +l2_pgentry_t *l2t =map_xen_pagetable_new ( +l3e_get_mfn (l3t[l3_table_offset (stub_linear)])); +l1_pgentry_t *l1t =map_xen_pagetable_new ( +l2e_get_mfn (l2t[l2_table_offset (stub_linear)])); l1t[l1_table_offset (stub_linear)] =l1e_empty (); + +UNMAP_XEN_PAGETABLE_NEW (l1t); +UNMAP_XEN_PAGETABLE_NEW (l2t); +UNMAP_XEN_PAGETABLE_NEW (l3t); } }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 51/84 x86/pv: properly map and unmap page tables in mark_pv_pt_pages_rdonly
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/pv/dom0_build.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
xen/arch/x86/pv/dom0_build.c +23 -12
@@ -50,17 +50,17 @@ static __init void mark_pv_pt_pages_rdonly(struct domain *d,unsigned long count;struct page_info *page;l4_pgentry_t *pl4e; -l3_pgentry_t *pl3e; -l2_pgentry_t *pl2e; -l1_pgentry_t *pl1e; +l3_pgentry_t *pl3e, *l3t; +l2_pgentry_t *pl2e, *l2t; +l1_pgentry_t *pl1e, *l1t; pl4e = l4start +l4_table_offset (vpt_start); - pl3e =l4e_to_l3e (*pl4e); - pl3e +=l3_table_offset (vpt_start); - pl2e =l3e_to_l2e (*pl3e); - pl2e +=l2_table_offset (vpt_start); - pl1e =l2e_to_l1e (*pl2e); - pl1e +=l1_table_offset (vpt_start); + l3t =map_xen_pagetable_new (l4e_get_mfn (*pl4e)); + pl3e = l3t +l3_table_offset (vpt_start); + l2t =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + pl2e = l2t +l2_table_offset (vpt_start); + l1t =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); + pl1e = l1t +l1_table_offset (vpt_start);for ( count =0 ; count < nr_pt_pages; count++ ) {l1e_remove_flags (*pl1e, _PAGE_RW);
@@ -85,12 +85,23 @@ static __init void mark_pv_pt_pages_rdonly(struct domain *d,if ( !((unsigned long )++pl2e & (PAGE_SIZE -1 )) ) {if ( !((unsigned long )++pl3e & (PAGE_SIZE -1 )) ) - pl3e =l4e_to_l3e (*++pl4e); - pl2e =l3e_to_l2e (*pl3e); + { +UNMAP_XEN_PAGETABLE_NEW (l3t); + l3t =map_xen_pagetable_new (l4e_get_mfn (*++pl4e)); + pl3e = l3t; + } +UNMAP_XEN_PAGETABLE_NEW (l2t); + l2t =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + pl2e = l2t; } - pl1e =l2e_to_l1e (*pl2e); +UNMAP_XEN_PAGETABLE_NEW (l1t); + l1t =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); + pl1e = l1t; } } +UNMAP_XEN_PAGETABLE_NEW (l1t); +UNMAP_XEN_PAGETABLE_NEW (l2t); +UNMAP_XEN_PAGETABLE_NEW (l3t); } static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn,
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 52/84 x86/pv: properly map and unmap page table in dom0_construct_pv
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/pv/dom0_build.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
xen/arch/x86/pv/dom0_build.c +5 -1
@@ -679,6 +679,8 @@ int __init dom0_construct_pv(struct domain *d,if (is_pv_32bit_domain (d) ) { +l2_pgentry_t *l2t; +/* Ensure the first four L3 entries are all populated. */ for ( i =0 , l3tab = l3start; i <4 ; ++i, ++l3tab ) {
@@ -693,7 +695,9 @@ int __init dom0_construct_pv(struct domain *d,l3e_get_page (*l3tab)->u.inuse.type_info |= PGT_pae_xen_l2; } -init_xen_pae_l2_slots (l3e_to_l2e (l3start[3 ]), d); + l2t =map_xen_pagetable_new (l3e_get_mfn (l3start[3 ])); +init_xen_pae_l2_slots (l2t, d); +UNMAP_XEN_PAGETABLE_NEW (l2t); }/* Pages that are part of page tables must be read only. */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 53/84 x86: remove lXe_to_lYe in __start_xen
In reply to [email protected]From: Wei Liu <[email protected]>
Properly map and unmap page tables where necessary.
--- xen/arch/x86/setup.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/setup.c +8 -2
@@ -1095,13 +1095,17 @@ void __init noreturn __start_xen(unsigned long mbi_p) pl4e =__va (__pa (idle_pg_table));for ( i =0 ; i <L4_PAGETABLE_ENTRIES ; i++, pl4e++ ) { +l3_pgentry_t *l3t; +if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) )continue ; *pl4e =l4e_from_intpte (l4e_get_intpte (*pl4e) + xen_phys_start); - pl3e =l4e_to_l3e (*pl4e); + pl3e = l3t =map_xen_pagetable_new (l4e_get_mfn (*pl4e));for ( j =0 ; j <L3_PAGETABLE_ENTRIES ; j++, pl3e++ ) { +l2_pgentry_t *l2t; +/* Not present, 1GB mapping, or already relocated? */ if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) || (l3e_get_flags(*pl3e) & _PAGE_PSE) ||
@@ -1109,7 +1113,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)continue ; *pl3e =l3e_from_intpte (l3e_get_intpte (*pl3e) + xen_phys_start); - pl2e =l3e_to_l2e (*pl3e); + pl2e = l2t =map_xen_pagetable_new (l3e_get_mfn (*pl3e));for ( k =0 ; k <L2_PAGETABLE_ENTRIES ; k++, pl2e++ ) {/* Not present, PSE, or already relocated? */
@@ -1120,7 +1124,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + xen_phys_start); } +UNMAP_XEN_PAGETABLE_NEW (l2t); } +UNMAP_XEN_PAGETABLE_NEW (l3t); }/* The only data mappings to be relocated are in the Xen area. */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 54/84 x86/mm: drop old page table APIs
In reply to [email protected]From: Wei Liu <[email protected]>
Now that we've switched all users to the new APIs, the old ones aren't needed anymore.
--- xen/arch/x86/mm.c | 16 ---------------- xen/include/asm-x86/mm.h | 2 -- xen/include/asm-x86/page.h | 5 ----- 3 files changed, 23 deletions(-)
xen/arch/x86/mm.c +0 -16
@@ -4850,22 +4850,6 @@ int mmcfg_intercept_write(return X86EMUL_OKAY ; } -void *alloc_xen_pagetable (void ) -{ -mfn_t mfn; - - mfn =alloc_xen_pagetable_new (); -ASSERT (!mfn_eq (mfn,INVALID_MFN )); - -return map_xen_pagetable_new (mfn); -} - -void free_xen_pagetable (void *v) -{ -if ( system_state != SYS_STATE_early_boot ) -free_xen_pagetable_new (virt_to_mfn (v)); -} -mfn_t alloc_xen_pagetable_new (void ) {if ( system_state != SYS_STATE_early_boot )
xen/include/asm-x86/mm.h +0 -2
@@ -631,8 +631,6 @@ int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int nr_frames, xen_pfn_t mfn_list[]);/* Allocator functions for Xen pagetables. */ -void *alloc_xen_pagetable (void ); -void free_xen_pagetable (void *v);mfn_t alloc_xen_pagetable_new (void );void *map_xen_pagetable_new (mfn_t mfn);void unmap_xen_pagetable_new (void *v);
xen/include/asm-x86/page.h +0 -5
@@ -187,11 +187,6 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)#define l4e_has_changed (x,y,flags) \ ( !!(((x).l4 ^ (y).l4) & ((PADDR_MASK&PAGE_MASK)|put_pte_flags(flags))) ) -/* Pagetable walking. */ -#define l2e_to_l1e (x) ((l1_pgentry_t *)__va(l2e_get_paddr(x))) -#define l3e_to_l2e (x) ((l2_pgentry_t *)__va(l3e_get_paddr(x))) -#define l4e_to_l3e (x) ((l3_pgentry_t *)__va(l4e_get_paddr(x))) -#define map_l1t_from_l2e (x) (l1_pgentry_t *)map_domain_page(l2e_get_mfn(x))#define map_l2t_from_l3e (x) (l2_pgentry_t *)map_domain_page(l3e_get_mfn(x))#define map_l3t_from_l4e (x) (l3_pgentry_t *)map_domain_page(l4e_get_mfn(x))
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 55/84 x86: switch to use domheap page for page tables
In reply to [email protected]From: Wei Liu <[email protected]>
Modify all the _new APIs to handle domheap pages.
--- xen/arch/x86/mm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
xen/arch/x86/mm.c +7 -6
@@ -4854,10 +4854,10 @@ mfn_t alloc_xen_pagetable_new(void) {if ( system_state != SYS_STATE_early_boot ) { -void *ptr =alloc_xenheap_page (); +struct page_info *pg =alloc_domheap_page (NULL ,0 ); -BUG_ON (!hardware_domain && !ptr); -return virt_to_mfn (ptr); +BUG_ON (!hardware_domain && !pg); +return pg ?page_to_mfn (pg) :INVALID_MFN ; }return alloc_boot_pages (1 ,1 );
@@ -4865,20 +4865,21 @@ mfn_t alloc_xen_pagetable_new(void)void *map_xen_pagetable_new (mfn_t mfn) { -return mfn_to_virt (mfn_x (mfn)); +return map_domain_page (mfn); }/* v can point to an entry within a table or be NULL */ void unmap_xen_pagetable_new (void *v) { -/* XXX still using xenheap page, no need to do anything. */ +if ( v ) +unmap_domain_page ((const void *)((unsigned long )v &PAGE_MASK )); }/* mfn can be INVALID_MFN */ void free_xen_pagetable_new (mfn_t mfn) {if ( system_state != SYS_STATE_early_boot && !mfn_eq (mfn,INVALID_MFN ) ) -free_xenheap_page (mfn_to_virt (mfn_x (mfn))); +free_domheap_page (mfn_to_page (mfn)); }static DEFINE_SPINLOCK (map_pgdir_lock);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 56/84 x86/mm: drop _new suffix for page table APIs
In reply to [email protected]From: Wei Liu <[email protected]>
--- xen/arch/x86/domain.c | 4 +- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/efi/runtime.h | 4 +- xen/arch/x86/mm.c | 164 +++++++++++++++++------------------ xen/arch/x86/pv/dom0_build.c | 28 +++--- xen/arch/x86/pv/shim.c | 12 +-- xen/arch/x86/setup.c | 8 +- xen/arch/x86/smpboot.c | 74 ++++++++-------- xen/arch/x86/x86_64/mm.c | 136 ++++++++++++++--------------- xen/common/efi/boot.c | 42 ++++----- xen/include/asm-x86/mm.h | 18 ++-- 11 files changed, 246 insertions(+), 246 deletions(-)
xen/arch/x86/domain.c +2 -2
@@ -1588,11 +1588,11 @@ void paravirt_ctxt_switch_to(struct vcpu *v)root_pgentry_t *rpt;mapcache_override_current (INVALID_VCPU ); - rpt =map_xen_pagetable_new (rpt_mfn); + rpt =map_xen_pagetable (rpt_mfn); rpt[root_table_offset (PERDOMAIN_VIRT_START )] =l4e_from_page (v->domain->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW); -UNMAP_XEN_PAGETABLE_NEW (rpt); +UNMAP_XEN_PAGETABLE (rpt);mapcache_override_current (NULL ); }
xen/arch/x86/domain_page.c +1 -1
@@ -343,7 +343,7 @@ mfn_t domain_page_map_to_mfn(const void *ptr)l1_pgentry_t *pl1e =virt_to_xen_l1e (va);BUG_ON (!pl1e); l1e = *pl1e; -UNMAP_XEN_PAGETABLE_NEW (pl1e); +UNMAP_XEN_PAGETABLE (pl1e); }else {
xen/arch/x86/efi/runtime.h +2 -2
@@ -10,9 +10,9 @@ void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) {l4_pgentry_t *l4t; - l4t =map_xen_pagetable_new (efi_l4_mfn); + l4t =map_xen_pagetable (efi_l4_mfn);l4e_write (l4t + l4idx, l4e); -UNMAP_XEN_PAGETABLE_NEW (l4t); +UNMAP_XEN_PAGETABLE (l4t); } }#endif
xen/arch/x86/mm.c +82 -82
519 lines not on this page · raw message
xen/arch/x86/pv/dom0_build.c +14 -14
@@ -55,11 +55,11 @@ static __init void mark_pv_pt_pages_rdonly(struct domain *d,l1_pgentry_t *pl1e, *l1t; pl4e = l4start +l4_table_offset (vpt_start); - l3t =map_xen_pagetable_new (l4e_get_mfn (*pl4e)); + l3t =map_xen_pagetable (l4e_get_mfn (*pl4e)); pl3e = l3t +l3_table_offset (vpt_start); - l2t =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + l2t =map_xen_pagetable (l3e_get_mfn (*pl3e)); pl2e = l2t +l2_table_offset (vpt_start); - l1t =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); + l1t =map_xen_pagetable (l2e_get_mfn (*pl2e)); pl1e = l1t +l1_table_offset (vpt_start);for ( count =0 ; count < nr_pt_pages; count++ ) {
@@ -86,22 +86,22 @@ static __init void mark_pv_pt_pages_rdonly(struct domain *d, {if ( !((unsigned long )++pl3e & (PAGE_SIZE -1 )) ) { -UNMAP_XEN_PAGETABLE_NEW (l3t); - l3t =map_xen_pagetable_new (l4e_get_mfn (*++pl4e)); +UNMAP_XEN_PAGETABLE (l3t); + l3t =map_xen_pagetable (l4e_get_mfn (*++pl4e)); pl3e = l3t; } -UNMAP_XEN_PAGETABLE_NEW (l2t); - l2t =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); +UNMAP_XEN_PAGETABLE (l2t); + l2t =map_xen_pagetable (l3e_get_mfn (*pl3e)); pl2e = l2t; } -UNMAP_XEN_PAGETABLE_NEW (l1t); - l1t =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); +UNMAP_XEN_PAGETABLE (l1t); + l1t =map_xen_pagetable (l2e_get_mfn (*pl2e)); pl1e = l1t; } } -UNMAP_XEN_PAGETABLE_NEW (l1t); -UNMAP_XEN_PAGETABLE_NEW (l2t); -UNMAP_XEN_PAGETABLE_NEW (l3t); +UNMAP_XEN_PAGETABLE (l1t); +UNMAP_XEN_PAGETABLE (l2t); +UNMAP_XEN_PAGETABLE (l3t); } static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn,
@@ -695,9 +695,9 @@ int __init dom0_construct_pv(struct domain *d,l3e_get_page (*l3tab)->u.inuse.type_info |= PGT_pae_xen_l2; } - l2t =map_xen_pagetable_new (l3e_get_mfn (l3start[3 ])); + l2t =map_xen_pagetable (l3e_get_mfn (l3start[3 ]));init_xen_pae_l2_slots (l2t, d); -UNMAP_XEN_PAGETABLE_NEW (l2t); +UNMAP_XEN_PAGETABLE (l2t); }/* Pages that are part of page tables must be read only. */
xen/arch/x86/pv/shim.c +6 -6
@@ -171,11 +171,11 @@ static void __init replace_va_mapping(struct domain *d, l4_pgentry_t *l4start,l2_pgentry_t *pl2e;l1_pgentry_t *pl1e; - pl3e =map_xen_pagetable_new (l4e_get_mfn (*pl4e)); + pl3e =map_xen_pagetable (l4e_get_mfn (*pl4e)); pl3e +=l3_table_offset (va); - pl2e =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + pl2e =map_xen_pagetable (l3e_get_mfn (*pl3e)); pl2e +=l2_table_offset (va); - pl1e =map_xen_pagetable_new (l2e_get_mfn (*pl2e)); + pl1e =map_xen_pagetable (l2e_get_mfn (*pl2e)); pl1e +=l1_table_offset (va);put_page_and_type (mfn_to_page (l1e_get_mfn (*pl1e)));
@@ -183,9 +183,9 @@ static void __init replace_va_mapping(struct domain *d, l4_pgentry_t *l4start, *pl1e =l1e_from_mfn (mfn, (!is_pv_32bit_domain (d) ?L1_PROT :COMPAT_L1_PROT )); -UNMAP_XEN_PAGETABLE_NEW (pl1e); -UNMAP_XEN_PAGETABLE_NEW (pl2e); -UNMAP_XEN_PAGETABLE_NEW (pl3e); +UNMAP_XEN_PAGETABLE (pl1e); +UNMAP_XEN_PAGETABLE (pl2e); +UNMAP_XEN_PAGETABLE (pl3e); }static void evtchn_reserve (struct domain *d,unsigned int port)
xen/arch/x86/setup.c +4 -4
@@ -1101,7 +1101,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)continue ; *pl4e =l4e_from_intpte (l4e_get_intpte (*pl4e) + xen_phys_start); - pl3e = l3t =map_xen_pagetable_new (l4e_get_mfn (*pl4e)); + pl3e = l3t =map_xen_pagetable (l4e_get_mfn (*pl4e));for ( j =0 ; j <L3_PAGETABLE_ENTRIES ; j++, pl3e++ ) {l2_pgentry_t *l2t;
@@ -1113,7 +1113,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)continue ; *pl3e =l3e_from_intpte (l3e_get_intpte (*pl3e) + xen_phys_start); - pl2e = l2t =map_xen_pagetable_new (l3e_get_mfn (*pl3e)); + pl2e = l2t =map_xen_pagetable (l3e_get_mfn (*pl3e));for ( k =0 ; k <L2_PAGETABLE_ENTRIES ; k++, pl2e++ ) {/* Not present, PSE, or already relocated? */
@@ -1124,9 +1124,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + xen_phys_start); } -UNMAP_XEN_PAGETABLE_NEW (l2t); +UNMAP_XEN_PAGETABLE (l2t); } -UNMAP_XEN_PAGETABLE_NEW (l3t); +UNMAP_XEN_PAGETABLE (l3t); }/* The only data mappings to be relocated are in the Xen area. */
xen/arch/x86/smpboot.c +37 -37
211 lines not on this page · raw message
xen/arch/x86/x86_64/mm.c +68 -68
388 lines not on this page · raw message
xen/common/efi/boot.c +21 -21
113 lines not on this page · raw message
xen/include/asm-x86/mm.h +9 -9
@@ -631,15 +631,15 @@ int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int nr_frames, xen_pfn_t mfn_list[]);/* Allocator functions for Xen pagetables. */ -mfn_t alloc_xen_pagetable_new (void ); -void *map_xen_pagetable_new (mfn_t mfn); -void unmap_xen_pagetable_new (void *v); -void free_xen_pagetable_new (mfn_t mfn); - -#define UNMAP_XEN_PAGETABLE_NEW (ptr) \ - do { \ - unmap_xen_pagetable_new((ptr)); \ - (ptr) = NULL; \ +mfn_t alloc_xen_pagetable (void ); +void *map_xen_pagetable (mfn_t mfn); +void unmap_xen_pagetable (void *v); +void free_xen_pagetable (mfn_t mfn); + +#define UNMAP_XEN_PAGETABLE (ptr) \ + do { \ + unmap_xen_pagetable((ptr)); \ + (ptr) = NULL; \ } while (0)l1_pgentry_t *virt_to_xen_l1e (unsigned long v);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 57/84 x86: add Persistent Map (PMAP) infrastructure
In reply to [email protected]From: Wei Liu <[email protected]>
The basic idea is like Persistent Kernel Map (PKMAP) in linux. We pre-populate all the relevant page tables before system is fully set up.
It is needed to bootstrap map domain page infrastructure -- we need some way to map pages to set up per-cpu region without a direct map.
In order to keep the number of entries minimal, this infrastructure can only be used by one CPU at a time.
--- xen/arch/x86/Makefile | 1 + xen/arch/x86/pmap.c | 82 ++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/fixmap.h | 3 ++ xen/include/asm-x86/pmap.h | 12 ++++++ 4 files changed, 98 insertions(+) create mode 100644 xen/arch/x86/pmap.c create mode 100644 xen/include/asm-x86/pmap.h
xen/arch/x86/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-y += pci.o obj-y += percpu.o obj-y += physdev.o x86_64/physdev.o obj-y += platform_hypercall.o x86_64/platform_hypercall.o +obj-y += pmap.o obj-y += psr.o obj-y += setup.o obj-y += shutdown.o
xen/arch/x86/pmap.c new file +82 -0
82 lines not on this page · raw message
xen/include/asm-x86/fixmap.h +3 -0
@@ -23,6 +23,7 @@#include <xen/kexec.h> #include <asm/apicdef.h> #include <asm/msi.h> +#include <asm/pmap.h> #include <acpi/apei.h> /*
@@ -48,6 +49,8 @@ enum fixed_addresses {FIX_XEN_SHARED_INFO , #endif /* CONFIG_XEN_GUEST *//* Everything else should go further down. */ +FIX_PMAP_BEGIN , +FIX_PMAP_END =FIX_PMAP_BEGIN +NUM_FIX_PMAP -1 ,FIX_APIC_BASE ,FIX_IO_APIC_BASE_0 , FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
xen/include/asm-x86/pmap.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef __X86_PMAP_H__ +#define __X86_PMAP_H__ + +/* Large enough for mapping 5 levels of page tables */ +#define NUM_FIX_PMAP 5 + +void pmap_lock (void ); +void pmap_unlock (void ); +void *pmap_map (struct page_info *page); +void pmap_unmap (void *p); + +#endif /* __X86_PMAP_H__ */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 58/84 x86/mm: fix leaks in map_xen_pagetable.
In reply to [email protected]From: Hongyan Xia <[email protected]>
Not unmapping pages after map_xen_pagetable can leak the virtual address space over time. Also this fix makes vmap_to_mfn non-trivial to be a macro. There might be better options but move it into vmap.c for now.
--- xen/arch/x86/mm.c | 5 +---- xen/common/vmap.c | 13 +++++++++++++ xen/include/asm-arm/mm.h | 2 -- xen/include/asm-x86/page.h | 2 -- xen/include/xen/vmap.h | 3 +++ 5 files changed, 17 insertions(+), 8 deletions(-)
xen/arch/x86/mm.c +1 -4
@@ -5160,6 +5160,7 @@ int map_pages_to_xen( !(l2e_get_flags(ol2e) & _PAGE_PSE) )free_xen_pagetable (l2e_get_mfn (ol2e)); } +UNMAP_XEN_PAGETABLE (l2t);free_xen_pagetable (l2t_mfn); } }
@@ -5225,7 +5226,6 @@ int map_pages_to_xen(l3e_write_atomic (pl3e,l3e_from_mfn (l2t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l2t); - l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);
@@ -5346,7 +5346,6 @@ int map_pages_to_xen(l2e_write_atomic (pl2e,l2e_from_mfn (l1t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l1t); - l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);
@@ -5589,7 +5588,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) {l3e_write_atomic (pl3e,l3e_from_mfn (mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l2t); - l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);
@@ -5657,7 +5655,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)l2e_write_atomic (pl2e,l2e_from_mfn (mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l1t); - l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);
xen/common/vmap.c +13 -0
@@ -19,6 +19,19 @@ static unsigned int __read_mostly vm_end[VMAP_REGION_NR];/* lowest known clear bit in the bitmap */ static unsigned int vm_low[VMAP_REGION_NR ]; +mfn_t vmap_to_mfn (void *va) +{ +l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va)); +mfn_t ret =_mfn (l1e_get_pfn (*pl1e)); +unmap_xen_pagetable (pl1e); +return ret; +} + +struct page_info *vmap_to_page (void *va) +{ +return mfn_to_page (vmap_to_mfn (va)); +} +void __init vm_init_type (enum vmap_region type,void *start,void *end) {unsigned int i, nr;
xen/include/asm-arm/mm.h +0 -2
@@ -231,8 +231,6 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga))#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn))#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) -#define vmap_to_mfn (va) maddr_to_mfn(virt_to_maddr((vaddr_t)va)) -#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va))/* Page-align address and convert to frame number format */ #define paddr_to_pfn_aligned (paddr) paddr_to_pfn(PAGE_ALIGN(paddr))
xen/include/asm-x86/page.h +0 -2
@@ -266,8 +266,6 @@ void copy_page_sse2(void *, const void *);#define pfn_to_paddr (pfn) __pfn_to_paddr(pfn)#define paddr_to_pfn (pa) __paddr_to_pfn(pa)#define paddr_to_pdx (pa) pfn_to_pdx(paddr_to_pfn(pa)) -#define vmap_to_mfn (va) _mfn(l1e_get_pfn(*virt_to_xen_l1e((unsigned long)(va)))) -#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va))#endif /* !defined(__ASSEMBLY__) */
xen/include/xen/vmap.h +3 -0
@@ -23,6 +23,9 @@ void *vmalloc_xen(size_t size);void *vzalloc (size_t size);void vfree (void *va); +mfn_t vmap_to_mfn (void *va); +struct page_info *vmap_to_page (void *va); +void __iomem *ioremap (paddr_t ,size_t );static inline void iounmap (void __iomem *va)
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 58/84] x86/mm: fix leaks in map_xen_pagetable.
Hi,
NIT: we don't usually add full stop at the end of the title. This applies for the rest of the series.
Quoted 64 lines · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Not unmapping pages after
map_xen_pagetablecan leak the virtual address space over time. Also this fix makesvmap_to_mfnnon-trivial to be a macro. There might be better options but move it intovmap.cfor now.Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/mm.c | 5 +---- xen/common/vmap.c | 13 +++++++++++++ xen/include/asm-arm/mm.h | 2 -- xen/include/asm-x86/page.h | 2 -- xen/include/xen/vmap.h | 3 +++ 5 files changed, 17 insertions(+), 8 deletions(-)xen/arch/x86/mm.c +1
-4@@ -5160,6 +5160,7 @@ int map_pages_to_xen( !(l2e_get_flags(ol2e) & _PAGE_PSE) )free_xen_pagetable (l2e_get_mfn (ol2e)); } +UNMAP_XEN_PAGETABLE (l2t);free_xen_pagetable (l2t_mfn); } }@@ -5225,7 +5226,6 @@ int map_pages_to_xen(l3e_write_atomic (pl3e,l3e_from_mfn (l2t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l2t); - l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);@@ -5346,7 +5346,6 @@ int map_pages_to_xen(l2e_write_atomic (pl2e,l2e_from_mfn (l1t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l1t); - l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);@@ -5589,7 +5588,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) {l3e_write_atomic (pl3e,l3e_from_mfn (mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l2t); - l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);@@ -5657,7 +5655,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)l2e_write_atomic (pl2e,l2e_from_mfn (mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l1t); - l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);xen/common/vmap.c +0
-0
xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 25
Quoted 7 lines
xen/common/vmap.c +4
-0@@ -19,6 +19,19 @@ static unsigned int __read_mostly vm_end[VMAP_REGION_NR];/* lowest known clear bit in the bitmap */ static unsigned int vm_low[VMAP_REGION_NR ]; +mfn_t vmap_to_mfn (void *va) +{ +l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va)); +mfn_t ret =_mfn (l1e_get_pfn (*pl1e));
We already
xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 26
Quoted 1 line
xen/common/vmap.c +1
-0+unmap_xen_pagetable (pl1e);
My knowledge of the x86 port is quite limited, but this feels suspicious to see an unmap in a function call vmap_to_mfn(). Where does is the map done?
Furthermore, this is not going to compile on Arm. You probably want to implement this function in x86 code and keep the current implementation for Arm.
xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 33
Quoted 7 lines
xen/common/vmap.c +7
-0+return ret; +} + +struct page_info *vmap_to_page (void *va) +{ +return mfn_to_page (vmap_to_mfn (va)); +}
This is the exact same implementation as in mm.h. So what's the advantage of this?
Quoted 36 lines
xen/common/vmap.c +1
-0+void __init vm_init_type (enum vmap_region type,void *start,void *end) {unsigned int i, nr;xen/include/asm-arm/mm.h +0
-2@@ -231,8 +231,6 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga))#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn))#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) -#define vmap_to_mfn (va) maddr_to_mfn(virt_to_maddr((vaddr_t)va)) -#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va))/* Page-align address and convert to frame number format */ #define paddr_to_pfn_aligned (paddr) paddr_to_pfn(PAGE_ALIGN(paddr))xen/include/asm-x86/page.h +0
-2@@ -266,8 +266,6 @@ void copy_page_sse2(void *, const void *);#define pfn_to_paddr (pfn) __pfn_to_paddr(pfn)#define paddr_to_pfn (pa) __paddr_to_pfn(pa)#define paddr_to_pdx (pa) pfn_to_pdx(paddr_to_pfn(pa)) -#define vmap_to_mfn (va) _mfn(l1e_get_pfn(*virt_to_xen_l1e((unsigned long)(va)))) -#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va))#endif /* !defined(__ASSEMBLY__) */ xen/include/xen/vmap.h +0
-0
xen/include/xen/vmap.h void *vmalloc_xen(size_t size); · line 31
Quoted 9 lines
xen/include/xen/vmap.h +3
-0@@ -23,6 +23,9 @@ void *vmalloc_xen(size_t size);void *vzalloc (size_t size);void vfree (void *va); +mfn_t vmap_to_mfn (void *va); +struct page_info *vmap_to_page (void *va); +void __iomem *ioremap (paddr_t ,size_t );static inline void iounmap (void __iomem *va)
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 58/84] x86/mm: fix leaks in map_xen_pagetable.
Quoted 3 lines · Julien Grall
Hi,
NIT: we don't usually add full stop at the end of the title. This applies for the rest of the series.
Thanks.
Quoted 77 lines · On 9/26/19 10:46 AM, [email protected] wrote:
Quoted 66 lines
From: Hongyan Xia <[email protected]>
Not unmapping pages after
map_xen_pagetablecan leak the virtual address space over time. Also this fix makesvmap_to_mfnnon-trivial to be a macro. There might be better options but move it intovmap.cfor now.Signed-off-by Hongyan Xia <[email protected]>---
xen/arch/x86/mm.c | 5 +----
xen/common/vmap.c | 13 +++++++++++++
xen/include/asm-arm/mm.h | 2 --
xen/include/asm-x86/page.h| 2 --
xen/include/xen/vmap.h | 3 +++5 files changed, 17 insertions(+), 8 deletions(-)xen/arch/x86/mm.c +1
-3@@ -5160,6 +5160,7 @@ int map_pages_to_xen( !(l2e_get_flags(ol2e) & _PAGE_PSE) ) free_xen_pagetable(l2e_get_mfn(ol2e)); } + UNMAP_XEN_PAGETABLE(l2t); free_xen_pagetable(l2t_mfn); } }@@ -5225,7 +5226,6 @@ int map_pages_to_xen( l3e_write_atomic(pl3e, l3e_from_mfn(l2t_mfn, __PAGE_HYPERVISOR)); UNMAP_XEN_PAGETABLE(l2t); - l2t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock);@@ -5346,7 +5346,6 @@ int map_pages_to_xen( l2e_write_atomic(pl2e, l2e_from_mfn(l1t_mfn, __PAGE_HYPERVISOR)); UNMAP_XEN_PAGETABLE(l1t); - l1t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock);@@ -5589,7 +5588,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) { l3e_write_atomic(pl3e, l3e_from_mfn(mfn, __PAGE_HYPERVISOR)); UNMAP_XEN_PAGETABLE(l2t); - l2t = NULL; } if ( locking )
spin_unlock(&map_pgdir_lock);xen/arch/x86/mm.c +0
-1@@ -5657,7 +5655,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) l2e_write_atomic(pl2e, l2e_from_mfn(mfn, __PAGE_HYPERVISOR)); UNMAP_XEN_PAGETABLE(l1t); - l1t = NULL; } if ( locking )
spin_unlock(&map_pgdir_lock);xen/common/vmap.c +0
-0xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 24
Quoted 6 lines
xen/common/vmap.c +4
-0@@ -19,6 +19,19 @@ static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; /* lowest known clear bit in the bitmap */ static unsigned int vm_low[VMAP_REGION_NR]; +mfn_t vmap_to_mfn (void *va) +{ + l1_pgentry_t *pl1e = virt_to_xen_l1e((unsigned long)(va)); + mfn_t ret = _mfn(l1e_get_pfn(*pl1e));We already
Quoted 6 lines
xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 26
Quoted 1 line
xen/common/vmap.c +1
-0+ unmap_xen_pagetable(pl1e);My knowledge of the x86 port is quite limited, but this feels suspicious to see an unmap in a function call
vmap_to_mfn(). Where does is the map done?Furthermore, this is not going to compile on Arm. You probably want to implement this function in x86 code and keep the current implementation for Arm.
Without the direct map, Xen page tables are accessed after mapping them into the address space with map_domain_page(), and unmapped when done. To read the l1e for the vmap, the page the l1e is in is first mapped, then the mfn is read, then the page is unmapped.
This series is based on 60 patches from Wei, so he might also be able to comment more on the details.
Quoted 10 lines
xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 33
Quoted 7 lines
xen/common/vmap.c +7
-0+ return ret; +} + +struct page_info *vmap_to_page (void *va) +{ + return mfn_to_page(vmap_to_mfn(va)); +}This is the exact same implementation as in
mm.h. So what's the advantage of this?
I agree. This can just be a macro.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 58/84] x86/mm: fix leaks in map_xen_pagetable.
Hi,
Quoted 87 lines · On 9/26/19 11:45 AM, [email protected] wrote:
Quoted 3 lines · Julien Grall
Hi,
NIT: we don't usually add full stop at the end of the title. This applies for the rest of the series.
Thanks.
Quoted 80 lines · On 9/26/19 10:46 AM, [email protected] wrote:
Quoted 68 lines
From: Hongyan Xia <[email protected]>
Not unmapping pages after
map_xen_pagetablecan leak the virtual address space over time. Also this fix makesvmap_to_mfnnon-trivial to be a macro. There might be better options but move it intovmap.cfor now.Signed-off-by Hongyan Xia <[email protected]>---
xen/arch/x86/mm.c | 5 +----
xen/common/vmap.c | 13 +++++++++++++
xen/include/asm-arm/mm.h | 2 --
xen/include/asm-x86/page.h| 2 --
xen/include/xen/vmap.h | 3 +++5 files changed, 17 insertions(+), 8 deletions(-)xen/arch/x86/mm.c +1
-2@@ -5160,6 +5160,7 @@ int map_pages_to_xen( !(l2e_get_flags(ol2e) & _PAGE_PSE) ) free_xen_pagetable(l2e_get_mfn(ol2e)); } + UNMAP_XEN_PAGETABLE(l2t); free_xen_pagetable(l2t_mfn); } }@@ -5225,7 +5226,6 @@ int map_pages_to_xen( l3e_write_atomic(pl3e, l3e_from_mfn(l2t_mfn, __PAGE_HYPERVISOR)); UNMAP_XEN_PAGETABLE(l2t); - l2t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock);@@ -5346,7 +5346,6 @@ int map_pages_to_xen( l2e_write_atomic(pl2e, l2e_from_mfn(l1t_mfn, __PAGE_HYPERVISOR)); UNMAP_XEN_PAGETABLE(l1t); - l1t = NULL; } if ( locking )
spin_unlock(&map_pgdir_lock);xen/arch/x86/mm.c +0
-1@@ -5589,7 +5588,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) { l3e_write_atomic(pl3e, l3e_from_mfn(mfn, __PAGE_HYPERVISOR)); UNMAP_XEN_PAGETABLE(l2t); - l2t = NULL; } if ( locking )
spin_unlock(&map_pgdir_lock);xen/arch/x86/mm.c +0
-1@@ -5657,7 +5655,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) l2e_write_atomic(pl2e, l2e_from_mfn(mfn,__PAGE_HYPERVISOR )); UNMAP_XEN_PAGETABLE(l1t); - l1t = NULL; }if ( locking )
spin_unlock(&map_pgdir_lock);xen/common/vmap.c +0
-0xen/common/vmap.c static unsigned int __read_mostly · line 25
Quoted 7 lines
xen/common/vmap.c +4
-0@@ -19,6 +19,19 @@ static unsigned int __read_mostly vm_end[VMAP_REGION_NR ]; /* lowest known clear bit in the bitmap */ static unsigned int vm_low[VMAP_REGION_NR]; +mfn_t vmap_to_mfn (void *va) +{ + l1_pgentry_t *pl1e = virt_to_xen_l1e((unsigned long)(va)); + mfn_t ret = _mfn(l1e_get_pfn(*pl1e));We already
Quoted 8 lines
Quoted 6 lines
xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 26
Quoted 1 line
xen/common/vmap.c +1
-0+ unmap_xen_pagetable(pl1e);My knowledge of the x86 port is quite limited, but this feels suspicious to see an unmap in a function call
vmap_to_mfn(). Where does is the map done?Furthermore, this is not going to compile on Arm. You probably want to implement this function in x86 code and keep the current implementation for Arm.
Without the direct map, Xen page tables are accessed after mapping them into the address space with
map_domain_page(), and unmapped when done. To read the l1e for the vmap, the page the l1e is in is first mapped, then the mfn is read, then the page is unmapped.
I am afraid I still don't understand. Maybe it will become clearer once the branch is provided.
Can you provide the exact call path where the corresponding map_domain_page will be done. Is is done by virt_to_xen_l1e()?
Quoted 2 lines
This series is based on 60 patches from Wei, so he might also be able to comment more on the details.
So is this a leak introduced by Wei's series?
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 58/84] x86/mm: fix leaks in map_xen_pagetable.
In reply to [email protected]Quoted 4 lines · On Thu, Sep 26, 2019 at 10:46:21AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Not unmapping pages after
map_xen_pagetablecan leak the virtual address space over time.
I understand this part, but ...
Quoted 3 lines
Also this fix makes
vmap_to_mfnnon-trivial to be a
macro. There might be better options but move it intovmap.cfor now.
... not this part.
Quoted 14 lines
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/mm.c | 5 +---- xen/common/vmap.c | 13 +++++++++++++ xen/include/asm-arm/mm.h | 2 -- xen/include/asm-x86/page.h | 2 -- xen/include/xen/vmap.h | 3 +++ 5 files changed, 17 insertions(+), 8 deletions(-)xen/arch/x86/mm.c +0
-0
xen/arch/x86/mm.c int map_pages_to_xen( · line 5163
Quoted 4 lines
xen/arch/x86/mm.c +1
-0@@ -5160,6 +5160,7 @@ int map_pages_to_xen( !(l2e_get_flags(ol2e) & _PAGE_PSE) )free_xen_pagetable (l2e_get_mfn (ol2e)); } +UNMAP_XEN_PAGETABLE (l2t);
This is presumably the issue you try to fix.
xen/arch/x86/mm.c int map_pages_to_xen( · line 5228
Quoted 8 lines
xen/arch/x86/mm.c +0
-1free_xen_pagetable (l2t_mfn); } }@@ -5225,7 +5226,6 @@ int map_pages_to_xen(l3e_write_atomic (pl3e,l3e_from_mfn (l2t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l2t); - l2t =NULL ;
This and similar changes below are irrelevant to the bug your try to fix.
UNMAP_XEN_PAGETABLE already sets lXt to NULL. Deleting these two lines are fine, but they should be folded into one of the previous patches where UNMAP_XEN_PAGETABLE was used in this function.
xen/common/vmap.c
Quoted 31 lines
xen/arch/x86/mm.c +0
-3}if ( locking )spin_unlock (&map_pgdir_lock);@@ -5346,7 +5346,6 @@ int map_pages_to_xen(l2e_write_atomic (pl2e,l2e_from_mfn (l1t_mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l1t); - l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);@@ -5589,7 +5588,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) {l3e_write_atomic (pl3e,l3e_from_mfn (mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l2t); - l2t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);@@ -5657,7 +5655,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)l2e_write_atomic (pl2e,l2e_from_mfn (mfn, __PAGE_HYPERVISOR));UNMAP_XEN_PAGETABLE (l1t); - l1t =NULL ; }if ( locking )spin_unlock (&map_pgdir_lock);xen/common/vmap.c +0
-0
I fail to see why you need to change vmap to fix a leak somewhere else.
I guess I will need to wait for your branch to have a closer look.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 58/84] x86/mm: fix leaks in map_xen_pagetable.
Quoted 14 lines · Wei Liu
xen/arch/x86/mm.c int map_pages_to_xen( · line 5163
Quoted 10 lines · On Thu, Sep 26, 2019 at 10:46:21AM +0100, [email protected] wrote:
xen/arch/x86/mm.c +1
-0@@ -5160,6 +5160,7 @@ int map_pages_to_xen( !(l2e_get_flags(ol2e) & _PAGE_PSE) )free_xen_pagetable (l2e_get_mfn (ol2e)); } +UNMAP_XEN_PAGETABLE (l2t);This is presumably the issue you try to fix.
Yes. Actually this patch fixes two issues, this is the first one.
Quoted 7 lines
xen/common/vmap.c
Quoted 4 lines
xen/common/vmap.c +0
-0I fail to see why you need to change vmap to fix a leak somewhere else.
The second leak is that after the patches, we cannot just call vmap_to_mfn() because it calls virt_to_xen_l1e() under the hood which maps a page. We have to unmap it, therefore I modified the vmap_to_mfn to also do the unmapping. This is a separate issue than the first one, so maybe I could split the patch into two.
Quoted 4 lines
I guess I will need to wait for your branch to have a closer look.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 59/84 x86/pmap: break the loop in pmap APIs.
In reply to [email protected]From: Hongyan Xia <[email protected]>
Modify the pmap PTEs directly. Using set/clear_fixmap() may result in invocation loops.
--- xen/arch/x86/pmap.c | 11 ++++++++--- xen/include/asm-x86/pmap.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
xen/arch/x86/pmap.c +8 -3
@@ -29,11 +29,12 @@ void pmap_unlock(void)spin_unlock (&lock); } -void *pmap_map (struct page_info *page) +void *pmap_map (mfn_t mfn) {unsigned int idx;void *linear =NULL ;enum fixed_addresses slot; +l1_pgentry_t *pl1e;ASSERT (!in_irq ());ASSERT (spin_is_locked (&lock));
@@ -47,7 +48,8 @@ void *pmap_map(struct page_info *page) slot = idx +FIX_PMAP_BEGIN ;ASSERT (slot >=FIX_PMAP_BEGIN && slot <=FIX_PMAP_END ); -set_fixmap (slot,mfn_x (page_to_mfn (page))); + pl1e = &l1_fixmap[L1_PAGETABLE_ENTRIES -1 - slot]; +l1e_write_atomic (pl1e,l1e_from_mfn (mfn,PAGE_HYPERVISOR )); linear = (void *)__fix_to_virt (slot);return linear;
@@ -56,6 +58,7 @@ void *pmap_map(struct page_info *page)void pmap_unmap (void *p) {unsigned int idx; +l1_pgentry_t *pl1e;enum fixed_addresses slot =__virt_to_fix ((unsigned long )p);ASSERT (!in_irq ());
@@ -64,7 +67,9 @@ void pmap_unmap(void *p) idx = slot -FIX_PMAP_BEGIN ;__clear_bit (idx, &inuse); -clear_fixmap (slot); + + pl1e = &l1_fixmap[L1_PAGETABLE_ENTRIES -1 - slot]; +l1e_write_atomic (pl1e,l1e_from_mfn (_mfn (0 ),0 )); }static void __maybe_unused build_assertions (void )
xen/include/asm-x86/pmap.h +1 -1
@@ -6,7 +6,7 @@void pmap_lock (void );void pmap_unlock (void ); -void *pmap_map (struct page_info *page); +void *pmap_map (mfn_t mfn);void pmap_unmap (void *p);#endif /* __X86_PMAP_H__ */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 59/84] x86/pmap: break the loop in pmap APIs.
Quoted 5 lines · On Thu, Sep 26, 2019 at 10:46:22AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Modify the pmap PTEs directly. Using set/clear_fixmap() may result in invocation loops.
Thanks. This is a good catch. I never got to test PMAP seriously.
This patch should be squashed into the patch that introduced PMAP. You will need too keep your SoB there.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 60/84 x86/domain_page: use PMAP when d/vcache is not ready.
In reply to [email protected]From: Hongyan Xia <[email protected]>
Also fix a place where unmap_domain_page should only be conditionally used.
--- xen/arch/x86/domain_page.c | 27 ++++++++++++++++++++++++--- xen/arch/x86/mm.c | 3 ++- 2 files changed, 26 insertions(+), 4 deletions(-)
xen/arch/x86/domain_page.c +24 -3
@@ -17,6 +17,8 @@#include <asm/flushtlb.h> #include <asm/hardirq.h> #include <asm/setup.h> +#include <asm/pmap.h> +#include <asm/fixmap.h> static DEFINE_PER_CPU(struct vcpu *, override);
@@ -83,12 +85,26 @@ void *map_domain_page(mfn_t mfn) v =mapcache_current_vcpu ();if ( !v || !is_pv_vcpu (v) ) -return mfn_to_virt (mfn_x (mfn)); + { +void *ret; +pmap_lock (); + ret =pmap_map (mfn); +pmap_unlock (); +flush_tlb_one_local (ret); +return ret; + } dcache = &v->domain->arch.pv.mapcache; vcache = &v->arch.pv.mapcache;if ( !dcache->inuse ) -return mfn_to_virt (mfn_x (mfn)); + { +void *ret; +pmap_lock (); + ret =pmap_map (mfn); +pmap_unlock (); +flush_tlb_one_local (ret); +return ret; + }perfc_incr (map_domain_page_count);
@@ -181,8 +197,13 @@ void unmap_domain_page(const void *ptr)unsigned long va = (unsigned long )ptr, mfn, flags;struct vcpu_maphash_entry *hashent; -if ( va >=DIRECTMAP_VIRT_START ) +if ( va >=FIXADDR_START && va <FIXADDR_TOP ) + { +pmap_lock (); +pmap_unmap ((void *)ptr); +pmap_unlock ();return ; + }ASSERT (va >=MAPCACHE_VIRT_START && va <MAPCACHE_VIRT_END );
xen/arch/x86/mm.c +2 -1
@@ -5949,7 +5949,8 @@ int create_perdomain_mapping(struct domain *d, unsigned long va,if ( rc || !nr || !l1_table_offset (va) ) {/* Note that this is a no-op for the alloc_xenheap_page() case. */ -unmap_domain_page (l1tab); +if ( (unsigned long )l1tab <DIRECTMAP_VIRT_START ) +unmap_domain_page (l1tab); l1tab =NULL ; } }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 60/84] x86/domain_page: use PMAP when d/vcache is not ready.
Quoted 25 lines · On Thu, Sep 26, 2019 at 10:46:23AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Also fix a place where
unmap_domain_pageshould only be conditionally used.Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/domain_page.c | 27 ++++++++++++++++++++++++--- xen/arch/x86/mm.c | 3 ++- 2 files changed, 26 insertions(+), 4 deletions(-)xen/arch/x86/domain_page.c +2
-0@@ -17,6 +17,8 @@#include <asm/flushtlb.h> #include <asm/hardirq.h> #include <asm/setup.h> +#include <asm/pmap.h> +#include <asm/fixmap.h> static DEFINE_PER_CPU(struct vcpu *, override);
xen/arch/x86/domain_page.c void *map_domain_page(mfn_t mfn) · line 93
Quoted 10 lines
xen/arch/x86/domain_page.c +6
-1@@ -83,12 +85,26 @@ void *map_domain_page(mfn_t mfn) v =mapcache_current_vcpu ();if ( !v || !is_pv_vcpu (v) ) -return mfn_to_virt (mfn_x (mfn)); + { +void *ret; +pmap_lock (); + ret =pmap_map (mfn); +pmap_unlock (); +flush_tlb_one_local (ret);
Oh this is a side effect of manipulating PTEs directly, right? I would prefer you put the flush into pmap_map. Its caller shouldn't need to flush the VA.
If you do that, please do it in the commit that introduces PMAP as well.
I will need more time to understand the overall design in this series to make further comments.
Quoted 38 lines
xen/arch/x86/domain_page.c +16
-2+return ret; + } dcache = &v->domain->arch.pv.mapcache; vcache = &v->arch.pv.mapcache;if ( !dcache->inuse ) -return mfn_to_virt (mfn_x (mfn)); + { +void *ret; +pmap_lock (); + ret =pmap_map (mfn); +pmap_unlock (); +flush_tlb_one_local (ret); +return ret; + }perfc_incr (map_domain_page_count);@@ -181,8 +197,13 @@ void unmap_domain_page(const void *ptr)unsigned long va = (unsigned long )ptr, mfn, flags;struct vcpu_maphash_entry *hashent; -if ( va >=DIRECTMAP_VIRT_START ) +if ( va >=FIXADDR_START && va <FIXADDR_TOP ) + { +pmap_lock (); +pmap_unmap ((void *)ptr); +pmap_unlock ();return ; + }ASSERT (va >=MAPCACHE_VIRT_START && va <MAPCACHE_VIRT_END );xen/arch/x86/mm.c +0
-0
xen/arch/x86/mm.c int create_perdomain_mapping(struct domain *d, unsigned long va, · line 5953
Quoted 6 lines
xen/arch/x86/mm.c +2
-1@@ -5949,7 +5949,8 @@ int create_perdomain_mapping(struct domain *d, unsigned long va,if ( rc || !nr || !l1_table_offset (va) ) {/* Note that this is a no-op for the alloc_xenheap_page() case. */ -unmap_domain_page (l1tab); +if ( (unsigned long )l1tab <DIRECTMAP_VIRT_START ) +unmap_domain_page (l1tab);
If this is a fix to one of my previous patches, please split the change out and merge it there.
And then, call out the bug fix in the change log for that patch.
Wei.
Quoted 6 lines
xen/arch/x86/mm.c +0
-0l1tab =NULL ; } }Signature · 1 line
2.17.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 61/84 x86: lift domain mapcache to arch_domain
In reply to [email protected]From: Wei Liu <[email protected]>
It is going to be needed by HVM as well, because we want even HVM domain to have a per-domain mapcache.
No functional change.
--- xen/arch/x86/domain.c | 4 ++-- xen/arch/x86/domain_page.c | 10 ++++------ xen/include/asm-x86/domain.h | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-)
xen/arch/x86/domain.c +2 -2
@@ -617,6 +617,8 @@ int arch_domain_create(struct domain *d,psr_domain_init (d); +mapcache_domain_init (d); +if (is_hvm_domain (d) ) {if ( (rc =hvm_domain_initialise (d)) !=0 )
@@ -624,8 +626,6 @@ int arch_domain_create(struct domain *d, }else if (is_pv_domain (d) ) { -mapcache_domain_init (d); -if ( (rc =pv_domain_initialise (d)) !=0 ) goto fail; }
xen/arch/x86/domain_page.c +4 -6
@@ -94,7 +94,7 @@ void *map_domain_page(mfn_t mfn)return ret; } - dcache = &v->domain->arch.pv.mapcache; + dcache = &v->domain->arch.mapcache; vcache = &v->arch.pv.mapcache;if ( !dcache->inuse ) {
@@ -210,7 +210,7 @@ void unmap_domain_page(const void *ptr) v =mapcache_current_vcpu ();ASSERT (v &&is_pv_vcpu (v)); - dcache = &v->domain->arch.pv.mapcache; + dcache = &v->domain->arch.mapcache;ASSERT (dcache->inuse); idx =PFN_DOWN (va -MAPCACHE_VIRT_START );
@@ -254,11 +254,9 @@ void unmap_domain_page(const void *ptr)int mapcache_domain_init (struct domain *d) { -struct mapcache_domain *dcache = &d->arch.pv.mapcache; +struct mapcache_domain *dcache = &d->arch.mapcache;unsigned int bitmap_pages; -ASSERT (is_pv_domain (d)); -#ifdef NDEBUG if ( !mem_hotplug && max_page <=PFN_DOWN (__pa (HYPERVISOR_VIRT_END -1 )) )return 0 ;
@@ -282,7 +280,7 @@ int mapcache_domain_init(struct domain *d)int mapcache_vcpu_init (struct vcpu *v) {struct domain *d = v->domain; -struct mapcache_domain *dcache = &d->arch.pv.mapcache; +struct mapcache_domain *dcache = &d->arch.mapcache;unsigned long i;unsigned int ents = d->max_vcpus *MAPCACHE_VCPU_ENTRIES ;unsigned int nr =PFN_UP (BITS_TO_LONGS (ents) *sizeof (long ));
xen/include/asm-x86/domain.h +3 -3
@@ -260,9 +260,6 @@ struct pv_domain/* Mitigate L1TF with shadow/crashing? */ bool check_l1tf; -/* map_domain_page() mapping cache. */ -struct mapcache_domain mapcache; -struct cpuidmasks *cpuidmasks; };
@@ -295,6 +292,9 @@ struct arch_domainuint32_t pci_cf8;uint8_t cmos_idx; +/* map_domain_page() mapping cache. */ +struct mapcache_domain mapcache; +union {struct pv_domain pv;struct hvm_domain hvm;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 62/84 x86: lift vcpu mapcache to arch_vcpu
In reply to [email protected]From: Wei Liu <[email protected]>
It is going to be needed by HVM as well, because we want even HVM vcpu to have a per-vcpu mapcache.
No functional change.
--- xen/arch/x86/domain_page.c | 8 ++++---- xen/include/asm-x86/domain.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/domain_page.c +4 -4
@@ -95,7 +95,7 @@ void *map_domain_page(mfn_t mfn) } dcache = &v->domain->arch.mapcache; - vcache = &v->arch.pv.mapcache; + vcache = &v->arch.mapcache;if ( !dcache->inuse ) {void *ret;
@@ -215,7 +215,7 @@ void unmap_domain_page(const void *ptr) idx =PFN_DOWN (va -MAPCACHE_VIRT_START ); mfn =l1e_get_pfn (MAPCACHE_L1ENT (idx)); - hashent = &v->arch.pv.mapcache.hash[MAPHASH_HASHFN (mfn)]; + hashent = &v->arch.mapcache.hash[MAPHASH_HASHFN (mfn)];local_irq_save (flags);
@@ -285,7 +285,7 @@ int mapcache_vcpu_init(struct vcpu *v)unsigned int ents = d->max_vcpus *MAPCACHE_VCPU_ENTRIES ;unsigned int nr =PFN_UP (BITS_TO_LONGS (ents) *sizeof (long )); -if ( !is_pv_vcpu (v) || !dcache->inuse ) +if ( !dcache->inuse )return 0 ;if ( ents > dcache->entries )
@@ -312,7 +312,7 @@ int mapcache_vcpu_init(struct vcpu *v)BUILD_BUG_ON (MAPHASHENT_NOTINUSE <MAPCACHE_ENTRIES );for ( i =0 ; i <MAPHASH_ENTRIES ; i++ ) { -struct vcpu_maphash_entry *hashent = &v->arch.pv.mapcache.hash[i]; +struct vcpu_maphash_entry *hashent = &v->arch.mapcache.hash[i]; hashent->mfn = ~0UL ;/* never valid to map */ hashent->idx =MAPHASHENT_NOTINUSE ;
xen/include/asm-x86/domain.h +3 -3
@@ -477,9 +477,6 @@ struct arch_domainstruct pv_vcpu { -/* map_domain_page() mapping cache. */ -struct mapcache_vcpu mapcache; -struct trap_info *trap_ctxt;unsigned long gdt_frames[FIRST_RESERVED_GDT_PAGE ];
@@ -560,6 +557,9 @@ struct arch_vcpustruct vpmu_struct vpmu; +/* map_domain_page() mapping cache. */ +struct mapcache_vcpu mapcache; +/* Virtual Machine Extensions */ union {struct pv_vcpu pv;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 63/84 x86/domain_page: mapcache is no longer tied to pv.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/domain_page.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/domain_page.c +2 -2
@@ -84,7 +84,7 @@ void *map_domain_page(mfn_t mfn)#endif v =mapcache_current_vcpu (); -if ( !v || !is_pv_vcpu (v) ) +if ( !v ) {void *ret;pmap_lock ();
@@ -208,7 +208,7 @@ void unmap_domain_page(const void *ptr)ASSERT (va >=MAPCACHE_VIRT_START && va <MAPCACHE_VIRT_END ); v =mapcache_current_vcpu (); -ASSERT (v &&is_pv_vcpu (v)); +ASSERT (v); dcache = &v->domain->arch.mapcache;ASSERT (dcache->inuse);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 63/84] x86/domain_page: mapcache is no longer tied to pv.
Quoted 3 lines · On Thu, Sep 26, 2019 at 10:46:26AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Signed-off-by Hongyan Xia <[email protected]>
AIUI there is where we want to end up. I do wonder if this is the correct place for this patch though. The bottom line is we need to make sure the HVM path works before we can allow HVM to use it.
I don't have an answer yet. I will have to look at later patches.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 64/84 mapcache: initialise the mapcache even for the idle domain.
In reply to [email protected]From: Hongyan Xia <[email protected]>
In situations like in irqs or domain creation, PMAP cannot be used or the mapcache of that domain is simply not ready. We need to have a mapcache in the idle domain to map pages to deal with these.
After this patch, map_domain_page() completely gets rid of the direct map. The assertions ensure mappings only happen within PMAP or MAPCACHE regions. As a result, map_xen_pagetable() gets rid of the direct map as well.
--- xen/arch/x86/mm.c | 3 +++ xen/common/schedule.c | 1 + 2 files changed, 4 insertions(+)
xen/arch/x86/mm.c +3 -0
@@ -5858,6 +5858,9 @@ int create_perdomain_mapping(struct domain *d, unsigned long va, l3tab =__map_domain_page (pg);clear_page (l3tab); d->arch.perdomain_l3_pg = pg; +if (is_idle_domain (d) ) + idle_pg_table[l4_table_offset (PERDOMAIN_VIRT_START )] = +l4e_from_page (pg, __PAGE_HYPERVISOR_RW);if ( !nr ) {unmap_domain_page (l3tab);
xen/common/schedule.c +1 -0
@@ -1814,6 +1814,7 @@ void __init scheduler_init(void)BUG_ON (nr_cpu_ids >ARRAY_SIZE (idle_vcpu)); idle_domain->vcpu = idle_vcpu; idle_domain->max_vcpus = nr_cpu_ids; +mapcache_domain_init (idle_domain);if (vcpu_create (idle_domain,0 ,0 ) ==NULL )BUG ();this_cpu (schedule_data).sched_priv =sched_alloc_pdata (&ops,0 );
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 65/84 x86: fix some wrong assumptions on direct map. Increase PMAP slots to 8.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/domain_page.c | 8 -------- xen/arch/x86/x86_64/mm.c | 3 ++- xen/include/asm-x86/pmap.h | 4 ++-- 3 files changed, 4 insertions(+), 11 deletions(-)
xen/arch/x86/domain_page.c +0 -8
@@ -328,11 +328,6 @@ void *map_domain_page_global(mfn_t mfn) system_state < SYS_STATE_active) || local_irq_is_enabled())); -#ifdef NDEBUG -if (mfn_x (mfn) <=PFN_DOWN (__pa (HYPERVISOR_VIRT_END -1 )) ) -return mfn_to_virt (mfn_x (mfn)); -#endif -return vmap (&mfn,1 ); }
@@ -340,9 +335,6 @@ void unmap_domain_page_global(const void *ptr) {unsigned long va = (unsigned long )ptr; -if ( va >=DIRECTMAP_VIRT_START ) -return ; -ASSERT (va >=VMAP_VIRT_START && va <VMAP_VIRT_END );vunmap (ptr);
xen/arch/x86/x86_64/mm.c +2 -1
@@ -712,7 +712,8 @@ void __init paging_init(void)if (mfn_eq (l2_ro_mpt_mfn,INVALID_MFN ) ) goto nomem; l2_ro_mpt =map_xen_pagetable (l2_ro_mpt_mfn); - compat_idle_pg_table_l2 = l2_ro_mpt; +/* compat_idle_pg_table_l2 is used globally. */ + compat_idle_pg_table_l2 =map_domain_page_global (l2_ro_mpt_mfn);clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )],l3e_from_mfn (l2_ro_mpt_mfn, __PAGE_HYPERVISOR_RO));
xen/include/asm-x86/pmap.h +2 -2
@@ -1,8 +1,8 @@#ifndef __X86_PMAP_H__#define __X86_PMAP_H__ -/* Large enough for mapping 5 levels of page tables */ -#define NUM_FIX_PMAP 5 +/* Large enough for mapping 5 levels of page tables with some headroom */ +#define NUM_FIX_PMAP 8void pmap_lock (void );void pmap_unlock (void );
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 65/84] x86: fix some wrong assumptions on direct map. Increase PMAP slots to 8.
Quoted 14 lines · On Thu, Sep 26, 2019 at 10:46:28AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/domain_page.c | 8 -------- xen/arch/x86/x86_64/mm.c | 3 ++- xen/include/asm-x86/pmap.h | 4 ++-- 3 files changed, 4 insertions(+), 11 deletions(-)xen/arch/x86/domain_page.c +0
-0
xen/arch/x86/domain_page.c void *map_domain_page_global(mfn_t mfn) · line 335
Quoted 8 lines
xen/arch/x86/domain_page.c +0
-5@@ -328,11 +328,6 @@ void *map_domain_page_global(mfn_t mfn) system_state < SYS_STATE_active) || local_irq_is_enabled())); -#ifdef NDEBUG -if (mfn_x (mfn) <=PFN_DOWN (__pa (HYPERVISOR_VIRT_END -1 )) ) -return mfn_to_virt (mfn_x (mfn)); -#endif -
I wouldn't call this a wrong assumption.
This path is a fast path. The problem is it is not longer applicable in the new world.
I would change the commit message to something like:
Drop fast paths in map_domain_page_global API pair, because Xen will no longer have a direct map.
Quoted 18 lines
xen/arch/x86/domain_page.c +0
-3return vmap (&mfn,1 ); }@@ -340,9 +335,6 @@ void unmap_domain_page_global(const void *ptr) {unsigned long va = (unsigned long )ptr; -if ( va >=DIRECTMAP_VIRT_START ) -return ; -ASSERT (va >=VMAP_VIRT_START && va <VMAP_VIRT_END );vunmap (ptr);xen/arch/x86/x86_64/mm.c +0
-0
xen/arch/x86/x86_64/mm.c void __init paging_init(void) · line 716
Quoted 6 lines
xen/arch/x86/x86_64/mm.c +2
-1@@ -712,7 +712,8 @@ void __init paging_init(void)if (mfn_eq (l2_ro_mpt_mfn,INVALID_MFN ) ) goto nomem; l2_ro_mpt =map_xen_pagetable (l2_ro_mpt_mfn); - compat_idle_pg_table_l2 = l2_ro_mpt; +/* compat_idle_pg_table_l2 is used globally. */ + compat_idle_pg_table_l2 =map_domain_page_global (l2_ro_mpt_mfn);
Again, if this is a bug in a previous patch, it should be fixed there.
Quoted 8 lines
xen/arch/x86/x86_64/mm.c +0
-0clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )],l3e_from_mfn (l2_ro_mpt_mfn, __PAGE_HYPERVISOR_RO));xen/include/asm-x86/pmap.h +0
-0
xen/include/asm-x86/pmap.h line 6
Quoted 8 lines
xen/include/asm-x86/pmap.h +2
-2@@ -1,8 +1,8 @@#ifndef __X86_PMAP_H__#define __X86_PMAP_H__ -/* Large enough for mapping 5 levels of page tables */ -#define NUM_FIX_PMAP 5 +/* Large enough for mapping 5 levels of page tables with some headroom */ +#define NUM_FIX_PMAP 8
This looks rather arbitrary to me. Can you specify why extra slots are needed? The original justification for 5 is for page tables. Now obviously it is used for more than just mapping page tables. I'm worried that even 8 may not be enough.
Also, this change should either be in a separate patch or folded into PMAP patch itself.
Wei.
Quoted 5 lines
xen/include/asm-x86/pmap.h +0
-0void pmap_lock (void );void pmap_unlock (void );Signature · 1 line
2.17.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 66/84 x86/pv: domheap pages should be mapped while relocating initrd
In reply to [email protected]From: Wei Liu <[email protected]>
Xen shouldn't use domheap page as if they were xenheap pages. Map and unmap pages accordingly.
--- xen/arch/x86/pv/dom0_build.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
xen/arch/x86/pv/dom0_build.c +16 -2
@@ -523,18 +523,32 @@ int __init dom0_construct_pv(struct domain *d,if ( d->arch.physaddr_bitsize && ((mfn + count -1 ) >> (d->arch.physaddr_bitsize -PAGE_SHIFT )) ) { +unsigned int nr_pages; +unsigned int len = initrd_len; +struct page_info *pg; + order =get_order_from_pages (count); page =alloc_domheap_pages (d, order, MEMF_no_scrub);if ( !page )panic ("Not enough RAM for domain 0 initrd\n" ); + + nr_pages =1UL << order;for ( count = -count; order--; )if ( count & (1UL << order) ) {free_domheap_pages (page, order); page +=1UL << order; + nr_pages -=1UL << order; } -memcpy (page_to_virt (page),mfn_to_virt (initrd->mod_start), - initrd_len); + +for ( pg = page, i =0 ; i < nr_pages; i++, len -=PAGE_SIZE , pg++ ) + { +void *p =__map_domain_page (pg); +memcpy (p,mfn_to_virt (initrd->mod_start) + i *PAGE_SIZE , + len >PAGE_SIZE ?PAGE_SIZE : len); +unmap_domain_page (p); + } + mpt_alloc = (paddr_t )initrd->mod_start <<PAGE_SHIFT ;init_domheap_pages (mpt_alloc, mpt_alloc +PAGE_ALIGN (initrd_len));
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 67/84 x86/domain_page: remove direct map code and initialise idle mapcache.
In reply to [email protected]From: Hongyan Xia <[email protected]>
These are found in the NDEBUG build.
--- xen/arch/x86/domain_page.c | 10 ---------- 1 file changed, 10 deletions(-)
xen/arch/x86/domain_page.c +0 -10
@@ -78,11 +78,6 @@ void *map_domain_page(mfn_t mfn)struct mapcache_vcpu *vcache;struct vcpu_maphash_entry *hashent; -#ifdef NDEBUG -if (mfn_x (mfn) <=PFN_DOWN (__pa (HYPERVISOR_VIRT_END -1 )) ) -return mfn_to_virt (mfn_x (mfn)); -#endif - v =mapcache_current_vcpu ();if ( !v ) {
@@ -257,11 +252,6 @@ int mapcache_domain_init(struct domain *d)struct mapcache_domain *dcache = &d->arch.mapcache;unsigned int bitmap_pages; -#ifdef NDEBUG -if ( !mem_hotplug && max_page <=PFN_DOWN (__pa (HYPERVISOR_VIRT_END -1 )) ) -return 0 ; -#endif -BUILD_BUG_ON (MAPCACHE_VIRT_END +PAGE_SIZE * (3 +2 *PFN_UP (BITS_TO_LONGS (MAPCACHE_ENTRIES ) *sizeof (long ))) >MAPCACHE_VIRT_START + (PERDOMAIN_SLOT_MBYTES <<20 ));
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 67/84] x86/domain_page: remove direct map code and initialise idle mapcache.
Quoted 14 lines · On Thu, Sep 26, 2019 at 10:46:30AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
These are found in the NDEBUG build.
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/domain_page.c | 10 ---------- 1 file changed, 10 deletions(-)xen/arch/x86/domain_page.c +0
-0
xen/arch/x86/domain_page.c void *map_domain_page(mfn_t mfn) · line 85
Quoted 8 lines
xen/arch/x86/domain_page.c +0
-5@@ -78,11 +78,6 @@ void *map_domain_page(mfn_t mfn)struct mapcache_vcpu *vcache;struct vcpu_maphash_entry *hashent; -#ifdef NDEBUG -if (mfn_x (mfn) <=PFN_DOWN (__pa (HYPERVISOR_VIRT_END -1 )) ) -return mfn_to_virt (mfn_x (mfn)); -#endif -
Again, this is dropping a fast path. Where is the corresponding change to unamp_domain_page?
xen/arch/x86/domain_page.c int mapcache_domain_init(struct domain *d) · line 264
Quoted 12 lines
xen/arch/x86/domain_page.c +0
-5v =mapcache_current_vcpu ();if ( !v ) {@@ -257,11 +252,6 @@ int mapcache_domain_init(struct domain *d)struct mapcache_domain *dcache = &d->arch.mapcache;unsigned int bitmap_pages; -#ifdef NDEBUG -if ( !mem_hotplug && max_page <=PFN_DOWN (__pa (HYPERVISOR_VIRT_END -1 )) ) -return 0 ; -#endif -
This should be in its own commit with justification.
Wei.
Quoted 6 lines
xen/arch/x86/domain_page.c +0
-0BUILD_BUG_ON (MAPCACHE_VIRT_END +PAGE_SIZE * (3 +2 *PFN_UP (BITS_TO_LONGS (MAPCACHE_ENTRIES ) *sizeof (long ))) >MAPCACHE_VIRT_START + (PERDOMAIN_SLOT_MBYTES <<20 ));Signature · 1 line
2.17.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 68/84 page_alloc: actually do the mapping and unmapping on xenheap.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/common/page_alloc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
xen/common/page_alloc.c +16 -2
@@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe)void *alloc_xenheap_pages (unsigned int order,unsigned int memflags) {struct page_info *pg; +void *ret;ASSERT (!in_irq ());
@@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)if (unlikely (pg ==NULL ) )return NULL ; -memguard_unguard_range (page_to_virt (pg),1 << (order +PAGE_SHIFT )); + ret =page_to_virt (pg); +memguard_unguard_range (ret,1 << (order +PAGE_SHIFT )); +map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg), +1UL << order,PAGE_HYPERVISOR );return page_to_virt (pg); }
@@ -2165,6 +2169,8 @@ void free_xenheap_pages(void *v, unsigned int order)return ;memguard_guard_range (v,1 << (order +PAGE_SHIFT )); +ASSERT ((unsigned long )v >=DIRECTMAP_VIRT_START ); +map_pages_to_xen ((unsigned long )v,INVALID_MFN ,1UL << order, _PAGE_NONE);free_heap_pages (virt_to_page (v), order, false); }
@@ -2189,6 +2195,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) {struct page_info *pg;unsigned int i; +void *ret;ASSERT (!in_irq ());
@@ -2204,7 +2211,11 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)for ( i =0 ; i < (1u << order); i++ ) pg[i].count_info |= PGC_xen_heap; -return page_to_virt (pg); + ret =page_to_virt (pg); +map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg), +1UL << order,PAGE_HYPERVISOR ); + +return ret; }void free_xenheap_pages (void *v,unsigned int order)
@@ -2222,6 +2233,9 @@ void free_xenheap_pages(void *v, unsigned int order)for ( i =0 ; i < (1u << order); i++ ) pg[i].count_info &= ~PGC_xen_heap; +ASSERT ((unsigned long )v >=DIRECTMAP_VIRT_START ); +map_pages_to_xen ((unsigned long )v,INVALID_MFN ,1UL << order, _PAGE_NONE); +free_heap_pages (pg, order, true); }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
Hi,
NIT Title: Please remove full stop.
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please provide a description of what/why you are doing this in the commit message.
Also, IIRC, x86 always have !CONFIG_SEPARATE_XENHEAP. So can you explain why the path with separate xenheap is also modified?
Quoted 19 lines
Signed-off-by Hongyan Xia <[email protected]>--- xen/common/page_alloc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)xen/common/page_alloc.c +1
-0@@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe)void *alloc_xenheap_pages (unsigned int order,unsigned int memflags) {struct page_info *pg; +void *ret;ASSERT (!in_irq ());
xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) · line 2158
Quoted 8 lines
xen/common/page_alloc.c +4
-1@@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)if (unlikely (pg ==NULL ) )return NULL ; -memguard_unguard_range (page_to_virt (pg),1 << (order +PAGE_SHIFT )); + ret =page_to_virt (pg); +memguard_unguard_range (ret,1 << (order +PAGE_SHIFT )); +map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg), +1UL << order,PAGE_HYPERVISOR );
As mentioned earlier on for Arm, xenheap will always be mapped. So unless you have plan to tackle the Arm side as well, we should make sure that the behavior is not changed for Arm.
It feels to me we want to introduce a new Kconfig that is selected by x86 to tell whether the direct map is mapped. I would then implement maybe in xen/mm.h two stub (one for when the config is selected, the other when it is not).
xen/common/page_alloc.c void free_xenheap_pages(void *v, unsigned int order) · line 2172
Quoted 8 lines
xen/common/page_alloc.c +1
-0return page_to_virt (pg); }@@ -2165,6 +2169,8 @@ void free_xenheap_pages(void *v, unsigned int order)return ;memguard_guard_range (v,1 << (order +PAGE_SHIFT )); +ASSERT ((unsigned long )v >=DIRECTMAP_VIRT_START );
This define does not exist for Arm32 so it will break compilation.
Quoted 27 lines
xen/common/page_alloc.c +7
-1+map_pages_to_xen ((unsigned long )v,INVALID_MFN ,1UL << order, _PAGE_NONE);free_heap_pages (virt_to_page (v), order, false); }@@ -2189,6 +2195,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) {struct page_info *pg;unsigned int i; +void *ret;ASSERT (!in_irq ());@@ -2204,7 +2211,11 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)for ( i =0 ; i < (1u << order); i++ ) pg[i].count_info |= PGC_xen_heap; -return page_to_virt (pg); + ret =page_to_virt (pg); +map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg), +1UL << order,PAGE_HYPERVISOR ); + +return ret; }void free_xenheap_pages (void *v,unsigned int order)
xen/common/page_alloc.c void free_xenheap_pages(void *v, unsigned int order) · line 2241
Quoted 9 lines
xen/common/page_alloc.c +3
-0@@ -2222,6 +2233,9 @@ void free_xenheap_pages(void *v, unsigned int order)for ( i =0 ; i < (1u << order); i++ ) pg[i].count_info &= ~PGC_xen_heap; +ASSERT ((unsigned long )v >=DIRECTMAP_VIRT_START ); +map_pages_to_xen ((unsigned long )v,INVALID_MFN ,1UL << order, _PAGE_NONE); +free_heap_pages (pg, order, true); }
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
Hi,
Quoted 74 lines · Julien Grall
Hi,
NIT Title: Please remove full stop.
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please provide a description of what/why you are doing this in the commit message.
Also, IIRC, x86 always have !CONFIG_SEPARATE_XENHEAP. So can you explain why the path with separate xenheap is also modified?
Quoted 17 lines
Signed-off-by Hongyan Xia <[email protected]>---
xen/common/page_alloc.c| 18 ++++++++++++++++--1 file changed, 16 insertions(+), 2 deletions(-)xen/common/page_alloc.c +1
-0@@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; + void *ret; ASSERT(!in_irq());xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, · line 2158
Quoted 8 lines
xen/common/page_alloc.c +4
-1@@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) if ( unlikely(pg == NULL) ) return NULL; - memguard_unguard_range(page_to_virt(pg), 1 << (order + PAGE_SHIFT)); + ret = page_to_virt(pg); + memguard_unguard_range(ret, 1 << (order + PAGE_SHIFT)); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR);As mentioned earlier on for Arm, xenheap will always be mapped. So unless you have plan to tackle the Arm side as well, we should make sure that the behavior is not changed for Arm.
It feels to me we want to introduce a new
Kconfigthat is selected by x86 to tell whether the direct map is mapped. I would then implement maybe inxen/mm.htwo stub (one for when the config is selected, the other when it is not).xen/common/page_alloc.c void free_xenheap_pages(void *v, unsigned int · line 2172
Quoted 7 lines
xen/common/page_alloc.c +1
-0return page_to_virt(pg); }@@ -2165,6 +2169,8 @@ void free_xenheap_pages(void *v, unsigned int order) return; memguard_guard_range(v, 1 << (order + PAGE_SHIFT)); + ASSERT((unsigned long)v >= DIRECTMAP_VIRT_START);This define does not exist for Arm32 so it will break compilation.
Quoted 23 lines
xen/common/page_alloc.c +7
-1+ map_pages_to_xen((unsigned long)v, INVALID_MFN, 1UL << order, _PAGE_NONE); free_heap_pages(virt_to_page(v), order, false); }@@ -2189,6 +2195,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; unsigned int i; + void *ret; ASSERT(!in_irq());@@ -2204,7 +2211,11 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) for ( i = 0; i < (1u << order); i++ ) pg[i].count_info |= PGC_xen_heap; - return page_to_virt(pg); + ret = page_to_virt(pg); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR); + + return ret; } void free_xenheap_pages(void *v, unsigned int order)
Quoted 8 lines
xen/common/page_alloc.c void free_xenheap_pages(void *v, unsigned int · line 2239
Quoted 8 lines
xen/common/page_alloc.c +3
-0@@ -2222,6 +2233,9 @@ void free_xenheap_pages(void *v, unsigned int order) for ( i = 0; i < (1u << order); i++ ) pg[i].count_info &= ~PGC_xen_heap; + ASSERT((unsigned long)v >= DIRECTMAP_VIRT_START); + map_pages_to_xen((unsigned long)v, INVALID_MFN, 1UL << order, _PAGE_NONE); +
I forgot to mention one thing. Can you explain why you are using map_pages_to_xen and not destroy_xen_mappings here?
From my understanding, the former will not teardown intermediate pagetables. If this is what you want then please write it down in a comment. Note that Arm does not support _PAGE_NONE so something similar to implementation of vunmap would be necessary.
This might be a call for a helper to do it.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
Quoted 6 lines · Julien Grall
Hi,
I forgot to mention one thing. Can you explain why you are using
map_pages_to_xenand notdestroy_xen_mappingshere?From my understanding, the former will not teardown intermediate pagetables.
If this is what you want then please write it down in a comment. Note that Arm does not support_PAGE_NONEso something similar to implementation of vunmap would be necessary.
That is exactly my intention. Without an always-mapped direct map, mappings to the DIRECTMAP region are created/destroyed alongside xenheap allocations/deallocations. Performance-wise it probably makes less sense to actually tear down all pagetables and later allocate them again.
I can add a comment.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
In reply to Julien GrallQuoted 30 lines · Julien Grall
Hi,
NIT Title: Please remove full stop.
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please provide a description of what/why you are doing this in the commit message.
Also, IIRC, x86 always have !CONFIG_SEPARATE_XENHEAP. So can you explain why the path with separate xenheap is also modified?
Quoted 19 lines
Signed-off-by Hongyan Xia <[email protected]>---
xen/common/page_alloc.c| 18 ++++++++++++++++--1 file changed, 16 insertions(+), 2 deletions(-)xen/common/page_alloc.c +1
-0@@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; + void *ret; ASSERT(!in_irq());@@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) if ( unlikely(pg == NULL) )
Quoted 8 lines
xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) · line 2158
Quoted 6 lines
xen/common/page_alloc.c +4
-1return NULL; - memguard_unguard_range(page_to_virt(pg), 1 << (order + PAGE_SHIFT)); + ret = page_to_virt(pg); + memguard_unguard_range(ret, 1 << (order + PAGE_SHIFT)); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR);As mentioned earlier on for Arm, xenheap will always be mapped. So unless you have plan to tackle the Arm side as well, we should make sure that the behavior is not changed for Arm.
I can add an #ifdef for x86. Although I think if the Arm code is correct, this should still not break things. It breaks if a xenheap access is made even before allocation or after free, which I think is a bug.
Quoted 3 lines
It feels to me we want to introduce a new
Kconfigthat is selected by x86 to tell whether the direct map is mapped. I would then implement maybe inxen/mm.htwo stub (one for when the config is selected, the other when it is not).
I have the same question. Do we want to move forward with no direct map in x86 or do we want to have a compile-time config? If the performance is decent, I would prefer the former since this could be a big compile-time switch which leaves two branches of code to be maintained in the future.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
Hi,
Quoted 41 lines · On 9/26/19 12:18 PM, [email protected] wrote:
Quoted 31 lines · Julien Grall
Hi,
NIT Title: Please remove full stop.
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please provide a description of what/why you are doing this in the commit message.
Also, IIRC, x86 always have !CONFIG_SEPARATE_XENHEAP. So can you explain why the path with separate xenheap is also modified?
Quoted 20 lines
Signed-off-by Hongyan Xia <[email protected]>---
xen/common/page_alloc.c| 18 ++++++++++++++++--1 file changed, 16 insertions(+), 2 deletions(-)xen/common/page_alloc.c +1
-0@@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; + void *ret; ASSERT(!in_irq());@@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) if ( unlikely(pg == NULL) ) return NULL;Quoted 8 lines
xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) · line 2158
Quoted 6 lines
xen/common/page_alloc.c +4
-1- memguard_unguard_range(page_to_virt(pg), 1 << (order + PAGE_SHIFT)); + ret = page_to_virt(pg); + memguard_unguard_range(ret, 1 << (order + PAGE_SHIFT)); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR);As mentioned earlier on for Arm, xenheap will always be mapped. So unless you have plan to tackle the Arm side as well, we should make sure that the behavior is not changed for Arm.
Quoted 1 line
I can add an #ifdef for x86. Although I think if the Arm code is correct, this should still not break things. It breaks if a xenheap access is made even before allocation or after free, which I think is a bug.
Correctness is a matter of perspective ;). xenheap is already map on Arm and therefore trying to map it again is considered as an error. I think this is a valid behavior because if you try to map twice then it likely means you may have to unmap later on.
Furthermore, xenheap is using superpage (2MB, 1GB) mapping at the moment. We completely forbid shattering superpage because they are not trivial to deal with.
In short, if you wanted to unmap part it, then you would need to shatter the page. Shattering superpage required to follow a specific sequence (called break-before-make) that will go through an invalid mapping. We need to be careful as another processor may access the superpage at the same time.
It may be possible to use only 4KB mapping for the xenheap, but that's need to be investigated first.
Lastly, not directly related to the discussion here, I think it would be a good time to start checking the return of map_pages_to_xen(). If the call unlikely fails, we would end up to continue and get an error later on that may be more difficult to debug. Instead, I would fail the allocation if the mapping is not done.
Quoted 5 lines
Quoted 4 lines
It feels to me we want to introduce a new
Kconfigthat is selected by x86 to tell whether the direct map is mapped. I would then implement maybe inxen/mm.htwo stub (one for when the config is selected, the other when it is not).I have the same question. Do we want to move forward with no direct map in x86 or do we want to have a compile-time config? If the performance is decent, I would prefer the former since this could be a big compile-time switch which leaves two branches of code to be maintained in the future.
Unless you have plan to implement the Arm bits, we will need two branches to maintain.
But what I suggested is x86 to always select the option that will require map/unmap the direct map. Arm would keep it disable.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
Quoted 43 lines · Julien Grall
Hi,
Quoted 40 lines · On 9/26/19 12:18 PM, [email protected] wrote:
Quoted 38 lines · Julien Grall
Hi,
NIT Title: Please remove full stop.
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please provide a description of what/why you are doing this in the commit message.
Also, IIRC, x86 always have !CONFIG_SEPARATE_XENHEAP. So can you explain why the path with separate xenheap is also modified?
Quoted 17 lines
Signed-off-by Hongyan Xia <[email protected]>---
xen/common/page_alloc.c| 18 ++++++++++++++++--1 file changed, 16 insertions(+), 2 deletions(-)xen/common/page_alloc.c +1
-0@@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; + void *ret; ASSERT(!in_irq());xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, · line 2158
Quoted 8 lines
xen/common/page_alloc.c +4
-1@@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) if ( unlikely(pg == NULL) ) return NULL; - memguard_unguard_range(page_to_virt(pg), 1 << (order + PAGE_SHIFT)); + ret = page_to_virt(pg); + memguard_unguard_range(ret, 1 << (order + PAGE_SHIFT)); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR);As mentioned earlier on for Arm, xenheap will always be mapped. So unless you have plan to tackle the Arm side as well, we should make sure that the behavior is not changed for Arm.
Quoted 3 lines
Quoted 1 line
I can add an #ifdef for x86. Although I think if the Arm code is correct, this should still not break things. It breaks if a xenheap access is made even before allocation or after free, which I think is a bug.
Correctness is a matter of perspective ;). xenheap is already map on Arm and therefore trying to map it again is considered as an error. I think this is a valid behavior because if you try to map twice then it likely means you may have to unmap later on.
Good point. Thanks. Will an ifdef do the job?
Quoted 6 lines
Furthermore, xenheap is using superpage (2MB, 1GB) mapping at the moment. We completely forbid shattering superpage because they are not trivial to deal with.
In short, if you wanted to unmap part it, then you would need to shatter the page. Shattering superpage required to follow a specific sequence (called break-before-make) that will go through an invalid mapping. We need to be careful as another processor may access the superpage at the same time.
It may be possible to use only 4KB mapping for the xenheap, but that's need to be investigated first.
The series is intended for x86 which then starts with no xenheap mappings. If one call to map_pages_to_xen() maps the first half of a superpage and a second one maps the remaining, will the second call merge them into an actual superpage mapping? Also, do we do a xenheap allocation and then only free part of it in some cases? If both answers are hopefully no, then shattering won't happen.
Quoted 7 lines
Lastly, not directly related to the discussion here, I think it would be a good time to start checking the return of
map_pages_to_xen(). If the call unlikely fails, we would end up to continue and get an error later on that may be more difficult to debug. Instead, I would fail the allocation if the mapping is not done.Quoted 4 lines
Quoted 4 lines
It feels to me we want to introduce a new
Kconfigthat is selected by x86 to tell whether the direct map is mapped. I would then implement maybe inxen/mm.htwo stub (one for when the config is selected, the other when it is not).
Quoted 8 lines
Quoted 1 line
I have the same question. Do we want to move forward with no direct map in x86 or do we want to have a compile-time config? If the performance is decent, I would prefer the former since this could be a big compile-time switch which leaves two branches of code to be maintained in the future.
Unless you have plan to implement the Arm bits, we will need two branches to maintain.
But what I suggested is x86 to always select the option that will require map/unmap the direct map. Arm would keep it disable.
Cheers,
Yes, that is what I meant. Sorry if it was not clear. I am happy with an ARM branch and an x86 one, but not super happy about x86 separated into two.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
Quoted 4 lines · On 26.09.2019 15:03, [email protected] wrote:
The series is intended for x86 which then starts with no xenheap mappings. If one call to
map_pages_to_xen()maps the first half of a superpage and a second one maps the remaining, will the second call merge them into an actual superpage mapping?
It will try to, yes.
Quoted 2 lines
Also, do we do a xenheap allocation and then only free part of it in some cases?
We do, yes.
What I'm severely confused by is how you word your questions. You surely had a need to understand both of these details before even posting the series, so other than this ...
Quoted 1 line
If both answers are hopefully no, then shattering won't happen.
... implies you should have known that the answers are "yes" in both cases.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap.
In reply to [email protected]Hi,
Quoted 45 lines · On 9/26/19 2:03 PM, [email protected] wrote:
Quoted 44 lines · Julien Grall
Hi,
Quoted 41 lines · On 9/26/19 12:18 PM, [email protected] wrote:
Quoted 39 lines · Julien Grall
Hi,
NIT Title: Please remove full stop.
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please provide a description of what/why you are doing this in the commit message.
Also, IIRC, x86 always have !CONFIG_SEPARATE_XENHEAP. So can you explain why the path with separate xenheap is also modified?
Quoted 17 lines
Signed-off-by Hongyan Xia <[email protected]>---
xen/common/page_alloc.c| 18 ++++++++++++++++--1 file changed, 16 insertions(+), 2 deletions(-)xen/common/page_alloc.c +1
-0@@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; + void *ret; ASSERT(!in_irq());xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int · line 2159
Quoted 9 lines
xen/common/page_alloc.c +4
-1@@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) if ( unlikely(pg == NULL) ) return NULL; - memguard_unguard_range(page_to_virt(pg), 1 << (order + PAGE_SHIFT)); + ret = page_to_virt(pg); + memguard_unguard_range(ret, 1 << (order + PAGE_SHIFT)); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR);As mentioned earlier on for Arm, xenheap will always be mapped. So unless you have plan to tackle the Arm side as well, we should make sure that the behavior is not changed for Arm.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I can add an #ifdef for x86. Although I think if the Arm code is correct, this should still not break things. It breaks if a xenheap access is made even before allocation or after free, which I think is a bug.
Correctness is a matter of perspective ;). xenheap is already map on Arm and therefore trying to map it again is considered as an error. I think this is a valid behavior because if you try to map twice then it likely means you may have to unmap later on.
Good point. Thanks. Will an ifdef do the job?
I would suggest to provide helpers so you can document in a single place why this is necessary and avoid to add #ifdefery everywhere.
Also, do we expect similar bits in other part of the common code? If yes, I would suggest to add those helpers in the header. If not, page_alloc.c should be enough.
Regarding the config name, I would rather not use CONFIG_X86 but use a new arch-agnostic one. Maybe CONFIG_DIRECTMAP_NOT_ALWAYS_MAPPED? (probably too verbose).
Quoted 9 lines
Quoted 7 lines
Furthermore, xenheap is using superpage (2MB, 1GB) mapping at the moment. We completely forbid shattering superpage because they are not trivial to deal with.
In short, if you wanted to unmap part it, then you would need to shatter the page. Shattering superpage required to follow a specific sequence (called break-before-make) that will go through an invalid mapping. We need to be careful as another processor may access the superpage at the same time.
It may be possible to use only 4KB mapping for the xenheap, but that's need to be investigated first.
The series is intended for x86 which then starts with no xenheap mappings. If one call to
map_pages_to_xen()maps the first half of a superpage and a second one maps the remaining, will the second call merge them into an actual superpage mapping? Also, do we do a xenheap allocation and then only free part of it in some cases? If both answers are hopefully no, then shattering won't happen.
For avoidance of doubt, I was describing how Arm works. For any x86 specific question, then Jan/Andrew are the best point of contact (I saw Jan already answered).
The main point is any common code should be able to work for any existing architecture (ATM x86, arm)
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 69/84 page_alloc: comments on (un)mapping pages in xenheap allocations.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/common/page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+)
xen/common/page_alloc.c +5 -0
@@ -2212,6 +2212,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) pg[i].count_info |= PGC_xen_heap; ret =page_to_virt (pg); +/* +* The direct map is not always mapped now. We need to populate the direct +* map region on demand for security. +*/ map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg),1UL << order,PAGE_HYPERVISOR );
@@ -2234,6 +2238,7 @@ void free_xenheap_pages(void *v, unsigned int order) pg[i].count_info &= ~PGC_xen_heap;ASSERT ((unsigned long )v >=DIRECTMAP_VIRT_START ); +/* Tear down the 1:1 mapping in this region for memory safety. */ map_pages_to_xen ((unsigned long )v,INVALID_MFN ,1UL << order, _PAGE_NONE);free_heap_pages (pg, order, true);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 69/84] page_alloc: comments on (un)mapping pages in xenheap allocations.
Hi,
Quoted 2 lines · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
This patch should be squashed in the previous patch (#68). This would also help review as it give more insight of why you need to map/unmap.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 70/84 x86/smpboot: use xenheap pages for rpts in smpboot.
In reply to [email protected]From: Hongyan Xia <[email protected]>
This is because a lot of code assumes that the rpt is in the direct map region which is always mapped. Switching to domheap is non-trivial, so use xenheap for now, which means a bit less security.
--- xen/arch/x86/smpboot.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
xen/arch/x86/smpboot.c +12 -7
@@ -832,14 +832,20 @@ static int setup_cpu_root_pgt(unsigned int cpu) goto out; } - rpt_mfn =alloc_xen_pagetable (); -if (mfn_eq (rpt_mfn,INVALID_MFN ) ) +/* +* Unfortunately, some code (especially in assembly) assumes the rpt is in +* the DIRECTMAP region and is always mapped. Making all of them adapt to +* the new page table APIs is non-trivial. For now, make it always mapped +* on the xenheap. +*/ + rpt =alloc_xenheap_page (); +if ( !rpt ) { rc = -ENOMEM ; goto out; } - rpt =map_xen_pagetable (rpt_mfn); + rpt_mfn =_mfn (virt_to_mfn (rpt));clear_page (rpt);per_cpu (root_pgt_mfn, cpu) = rpt_mfn;
@@ -884,7 +890,6 @@ static int setup_cpu_root_pgt(unsigned int cpu) rc =clone_mapping ((void *)per_cpu (stubs.addr, cpu), rpt); out: -UNMAP_XEN_PAGETABLE (rpt);return rc; }
@@ -900,7 +905,7 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)per_cpu (root_pgt_mfn, cpu) =INVALID_MFN ; - rpt =map_xen_pagetable (rpt_mfn); + rpt =mfn_to_virt (mfn_x (rpt_mfn));for ( r =root_table_offset (DIRECTMAP_VIRT_START ); r <root_table_offset (HYPERVISOR_VIRT_END ); ++r )
@@ -945,8 +950,8 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)free_xen_pagetable (l3t_mfn); } -UNMAP_XEN_PAGETABLE (rpt); -free_xen_pagetable (rpt_mfn); +/* Unlike other levels, the root level is a xenheap page. */ +free_xenheap_page (rpt);/* Also zap the stub mapping for this CPU. */ if ( stub_linear )
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 71/84 x86/setup: start tearing down the direct map.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/setup.c | 4 ++-- xen/common/page_alloc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/setup.c +2 -2
@@ -1367,7 +1367,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( map_e < end ) { -map_pages_to_xen ((unsigned long )__va (map_e),maddr_to_mfn (map_e), +map_pages_to_xen ((unsigned long )__va (map_e),INVALID_MFN ,PFN_DOWN (end - map_e),PAGE_HYPERVISOR );init_boot_pages (map_e, end); map_e = end;
@@ -1382,7 +1382,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) }if ( s < map_s ) { -map_pages_to_xen ((unsigned long )__va (s),maddr_to_mfn (s), +map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN ,PFN_DOWN (map_s - s),PAGE_HYPERVISOR );init_boot_pages (s, map_s); }
xen/common/page_alloc.c +1 -1
@@ -2157,7 +2157,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg),1UL << order,PAGE_HYPERVISOR ); -return page_to_virt (pg); +return ret; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
Hi,
Title: Please remove the full stop.
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please describe what the patch does and why. For instance, why you do you replace maddr_to_mfn(map_e) with INVALID_MFN? Why not just removing the complete call?
Quoted 34 lines
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/setup.c | 4 ++-- xen/common/page_alloc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)xen/arch/x86/setup.c +2
-2@@ -1367,7 +1367,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( map_e < end ) { -map_pages_to_xen ((unsigned long )__va (map_e),maddr_to_mfn (map_e), +map_pages_to_xen ((unsigned long )__va (map_e),INVALID_MFN ,PFN_DOWN (end - map_e),PAGE_HYPERVISOR );init_boot_pages (map_e, end); map_e = end;@@ -1382,7 +1382,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) }if ( s < map_s ) { -map_pages_to_xen ((unsigned long )__va (s),maddr_to_mfn (s), +map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN ,PFN_DOWN (map_s - s),PAGE_HYPERVISOR );init_boot_pages (s, map_s); }xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) · line 2160
Quoted 5 lines
xen/common/page_alloc.c +1
-1@@ -2157,7 +2157,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg),1UL << order,PAGE_HYPERVISOR ); -return page_to_virt (pg); +return ret;
This change looks spurious. Did you intend to do it in a previous patch?
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
In reply to [email protected]Quoted 13 lines · On Thu, Sep 26, 2019 at 10:46:34AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/setup.c | 4 ++-- xen/common/page_alloc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)xen/arch/x86/setup.c +0
-0
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1371
Quoted 6 lines
xen/arch/x86/setup.c +1
-1@@ -1367,7 +1367,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( map_e < end ) { -map_pages_to_xen ((unsigned long )__va (map_e),maddr_to_mfn (map_e), +map_pages_to_xen ((unsigned long )__va (map_e),INVALID_MFN ,PFN_DOWN (end - map_e),PAGE_HYPERVISOR );
Why don't you just remove the calls to map_pages_to_xen?
Quoted 16 lines
xen/arch/x86/setup.c +1
-1init_boot_pages (map_e, end); map_e = end;@@ -1382,7 +1382,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) }if ( s < map_s ) { -map_pages_to_xen ((unsigned long )__va (s),maddr_to_mfn (s), +map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN ,PFN_DOWN (map_s - s),PAGE_HYPERVISOR );init_boot_pages (s, map_s); }xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) · line 2160
Quoted 5 lines
xen/common/page_alloc.c +1
-1@@ -2157,7 +2157,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg),1UL << order,PAGE_HYPERVISOR ); -return page_to_virt (pg); +return ret;
This hunk is a fix to a previous patch. It doesn't below here.
Wei.
Quoted 6 lines
xen/common/page_alloc.c +0
-0}Signature · 1 line
2.17.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
Quoted 15 lines · Wei Liu
Quoted 14 lines · On Thu, Sep 26, 2019 at 10:46:34AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/setup.c | 4 ++-- xen/common/page_alloc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)xen/arch/x86/setup.c +0
-0@@ -1367,7 +1367,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 8 lines
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1371
Quoted 5 lines
xen/arch/x86/setup.c +1
-1if ( map_e < end ) { -map_pages_to_xen ((unsigned long )__va (map_e),maddr_to_mfn (map_e), +map_pages_to_xen ((unsigned long )__va (map_e),INVALID_MFN ,PFN_DOWN (end - map_e),PAGE_HYPERVISOR );Why don't you just remove the calls to
map_pages_to_xen?
My intention is to pre-populate the range so that we don't have to do so later when there are xenheap allocations. But of course if there is superpage merging or shattering, page tables will be removed or allocated anyway. I will remove the calls in the next revision.
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/setup.c +1
-1init_boot_pages (map_e, end); map_e = end;@@ -1382,7 +1382,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) }if ( s < map_s ) { -map_pages_to_xen ((unsigned long )__va (s),maddr_to_mfn (s), +map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN ,PFN_DOWN (map_s - s),PAGE_HYPERVISOR );init_boot_pages (s, map_s); }xen/common/page_alloc.c +0
-0@@ -2157,7 +2157,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags)map_pages_to_xen ((unsigned long )ret,page_to_mfn (pg),1UL << order,PAGE_HYPERVISOR );
Quoted 5 lines
xen/common/page_alloc.c void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) · line 2160
Quoted 2 lines
xen/common/page_alloc.c +1
-1-return page_to_virt (pg); +return ret;This hunk is a fix to a previous patch. It doesn't below here.
Noted.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
Quoted 15 lines · On 27.09.2019 14:54, [email protected] wrote:
Quoted 5 lines · Wei Liu
Quoted 4 lines · On Thu, Sep 26, 2019 at 10:46:34AM +0100, [email protected] wrote:
xen/arch/x86/setup.c +0
-0@@ -1367,7 +1367,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)Quoted 8 lines
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1371
Quoted 5 lines
xen/arch/x86/setup.c +1
-1if ( map_e < end ) { -map_pages_to_xen ((unsigned long )__va (map_e),maddr_to_mfn (map_e), +map_pages_to_xen ((unsigned long )__va (map_e),INVALID_MFN ,PFN_DOWN (end - map_e),PAGE_HYPERVISOR );Why don't you just remove the calls to
map_pages_to_xen?
Quoted 4 lines
My intention is to pre-populate the range so that we don't have to do so later when there are xenheap allocations. But of course if there is superpage merging or shattering, page tables will be removed or allocated anyway. I will remove the calls in the next revision.
Pre-populate? There's some conceptional question then: When the direct map is gone, are you mapping Xen heap pages into the place they'd have lived at in the direct map? I'm not convinced that's what we want. In fact I'm not convinced we'd want to retain the distinction between Xen heap and domain heap then any further - there's no reason anymore at that point (afaict).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
Quoted 8 lines · Jan Beulich
On 27.09.2019 14:54, [email protected] wrote:
Pre-populate? There's some conceptional question then: When the direct map is gone, are you mapping Xen heap pages into the place they'd have lived at in the direct map? I'm not convinced that's what we want. In fact I'm not convinced we'd want to retain the distinction between Xen heap and domain heap then any further - there's no reason anymore at that point (afaict).
Yes. My patches map xenheap pages to where they would have lived on the direct map region, and unmap when xenheap pages are freed. The original proposal was to use vmap() which we find difficult to implement.
- vmap takes an array of mfns. Mapping a large region require allocating/freeing memory for a large array of mfns, unless we change or add another vmap variant.
- va<->pa conversion. Mapping xenheap to direct map region makes all the xenheap conversion macros still work. The vmap proposal needs to add another field in page_info (breaking the power of 2) or to have a separate structure somewhere else for va/pa conversion.
Of course, we could change all the code for xenheap to use the same domheap mapping structure, which is probably another large patch series.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
Quoted 14 lines · On 27.09.2019 16:02, [email protected] wrote:
Quoted 8 lines · Jan Beulich
On 27.09.2019 14:54, [email protected] wrote:
Pre-populate? There's some conceptional question then: When the direct map is gone, are you mapping Xen heap pages into the place they'd have lived at in the direct map? I'm not convinced that's what we want. In fact I'm not convinced we'd want to retain the distinction between Xen heap and domain heap then any further - there's no reason anymore at that point (afaict).
Yes. My patches map xenheap pages to where they would have lived on the direct map region, and unmap when xenheap pages are freed. The original proposal was to use
vmap()which we find difficult to implement.
Quoted 7 lines
- vmap takes an array of mfns. Mapping a large region require allocating/freeing memory for a large array of mfns, unless we change or add another vmap variant.
- va<->pa conversion. Mapping xenheap to direct map region makes all the xenheap conversion macros still work. The vmap proposal needs to add another field inpage_info(breaking the power of 2) or to have a separate structure somewhere else for va/pa conversion.
But then why do the initial so many patches (inherited from Wei) convert from domheap to xenheap allocations at all? If your approach is to be at least an intermediate goal, then I think the order of changes should be such that on-demand mapping of xenheap pages occurs first, and then the xenheap -> domheap conversion can happen in basically arbitrarily small steps.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
Quoted 8 lines · Jan Beulich
On 27.09.2019 16:02, [email protected] wrote:
But then why do the initial so many patches (inherited from Wei) convert from domheap to xenheap allocations at all? If your approach is to be at least an intermediate goal, then I think the order of changes should be such that on-demand mapping of xenheap pages occurs first, and then the xenheap -> domheap conversion can happen in basically arbitrarily small steps.
There is this problem that anything that maps/unmaps memory in the direct map region cannot itself rely on an always-mapped direct map. Unfortunately, if I map/unmap xenheap allocations, page table manipulation functions (like map_pages_to_xen, alloc_xen_pagetable) themselves rely on an always-mapped direct map, which often break if you leave holes in the direct map region. Wei's patches with some of my later patches break exactly this dependency, so page table manipulations themselves no longer rely on the direct map. Now we can actually start tearing down the direct map, including on-demand mapping of xenheap in the direct map region.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
On 27.09.2019 16:02, [email protected] wrote:
But then why do the initial so many patches (inherited from Wei) convert from domheap to xenheap allocations at all? If your approach is to be at least an intermediate goal, then I think the order of changes should be such that on-demand mapping of xenheap pages occurs first, and then the xenheap -> domheap conversion can happen in basically arbitrarily small steps.
Also I have tested Wei's patches with fixes. It is pretty stable against my setup because the direct map has not been actually removed. I am able to run XTF tests, boot dom0, launch, restart and destroy guests without breakage. From a stability point of view, it probably makes more sense for Wei's patches to go in first. From the reviews, it looks like my patches to actually remove the direct map can benefit from more RFCs, and can be separated from Wei's into a second batch.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map.
In reply to [email protected]Hi,
Quoted 25 lines · On 27/09/2019 13:54, [email protected] wrote:
Quoted 9 lines · Wei Liu
Quoted 8 lines · On Thu, Sep 26, 2019 at 10:46:34AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Signed-off-by Hongyan Xia <[email protected]>---
xen/arch/x86/setup.c | 4 ++--
xen/common/page_alloc.c| 2 +-2 files changed, 3 insertions(+), 3 deletions(-)Quoted 14 lines
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1371
Quoted 11 lines
xen/arch/x86/setup.c +1
-1@@ -1367,7 +1367,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) if ( map_e < end ) { - map_pages_to_xen((unsigned long)__va(map_e),maddr_to_mfn (map_e), + map_pages_to_xen((unsigned long)__va(map_e), INVALID_MFN, PFN_DOWN(end - map_e), PAGE_HYPERVISOR);Why don't you just remove the calls to
map_pages_to_xen?
Quoted 1 line
My intention is to pre-populate the range so that we don't have to do so later when there are xenheap allocations. But of course if there is superpage merging or shattering, page tables will be removed or allocated anyway. I will remove the calls in the next revision.
How about using populate_pt_range() in that case? This will pre-populate the page-tables for mapping with small pages.
I haven't fully read the series yet. But I would assume that only memory allocated for Xen internal would be kept mapped. Guest memory would still be unmapped, right?
If so, I don't think we often do big allocation for Xen. So it is probably more likely to use small pages. In that case, it would be fine to pre-allocate pages.
In another hand, Xen doesn't use a lot of memory (if you compare to guest memory). So maybe pre-populating the page-tables would be a waste of memory.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 72/84 acpi: don't assume an always-mapped direct map in acpi allocations.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/drivers/acpi/osl.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
xen/drivers/acpi/osl.c +29 -12
@@ -216,14 +216,25 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)void *__init acpi_os_alloc_memory (size_t sz) { -void *ptr; - -if (system_state == SYS_STATE_early_boot) -return mfn_to_virt (mfn_x (alloc_boot_pages (PFN_UP (sz),1 ))); - - ptr =xmalloc_bytes (sz); -ASSERT (!ptr ||is_xmalloc_memory (ptr)); -return ptr; +void *ptr; +unsigned long nr_pfns =PFN_UP (sz); +mfn_t mfn; + +if (system_state == SYS_STATE_early_boot) + { + mfn =alloc_boot_pages (nr_pfns,1 ); + ptr =mfn_to_virt (mfn_x (mfn)); +/* +* Direct map is garbage now, fill the actual mapping. Safe to do so +* now because map_pages got rid of the direct map even in early boot. +*/ +map_pages_to_xen ((unsigned long )ptr, mfn, nr_pfns,PAGE_HYPERVISOR ); +return ptr; + } + + ptr =xmalloc_bytes (sz); +ASSERT (!ptr ||is_xmalloc_memory (ptr)); +return ptr; }void *__init acpi_os_zalloc_memory (size_t sz)
@@ -241,8 +252,14 @@ void *__init acpi_os_zalloc_memory(size_t sz)void __init acpi_os_free_memory (void *ptr) { -if (is_xmalloc_memory (ptr)) -xfree (ptr); -else if (ptr && system_state == SYS_STATE_early_boot) -init_boot_pages (__pa (ptr),__pa (ptr) +PAGE_SIZE ); +mfn_t mfn; +if (is_xmalloc_memory (ptr)) +xfree (ptr); +else if (ptr && system_state == SYS_STATE_early_boot) + { +init_boot_pages (__pa (ptr),__pa (ptr) +PAGE_SIZE ); +/* Also unmap in the 1:1 region for security. */ + mfn =_mfn (virt_to_mfn (ptr)); +map_pages_to_xen ((unsigned long )ptr, mfn,1 , _PAGE_NONE); + } }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 73/84 x86/mm: Move vmap_to_mfn() to mm.c and rename to virt_to_mfn_walk().
In reply to [email protected]From: Hongyan Xia <[email protected]>
Obviously, vmap_to_mfn is a generic mechanism to walk the page table to find the mfn, not vmap specific. Also the difference from virt_to_mfn() is that it actually walks the page table instead of relying on a direct map.
--- xen/arch/x86/mm.c | 13 +++++++++++++ xen/common/vmap.c | 15 +-------------- xen/include/asm-x86/mm.h | 2 ++ xen/include/xen/vmap.h | 3 --- 4 files changed, 16 insertions(+), 17 deletions(-)
xen/arch/x86/mm.c +13 -0
@@ -5056,6 +5056,19 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)return pl1e; } +unsigned long virt_to_mfn_walk (void *va) +{ +l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va)); +unsigned long ret =l1e_get_pfn (*pl1e); +unmap_xen_pagetable (pl1e); +return ret; +} + +struct page_info *virt_to_page_walk (void *va) +{ +return mfn_to_page (_mfn (virt_to_mfn_walk (va))); +} +/* Convert to from superpage-mapping flags for map_pages_to_xen(). */ #define l1f_to_lNf (f) (((f) & _PAGE_PRESENT) ? ((f) | _PAGE_PSE) : (f))#define lNf_to_l1f (f) (((f) & _PAGE_PRESENT) ? ((f) & ~_PAGE_PSE) : (f))
xen/common/vmap.c +1 -14
@@ -19,19 +19,6 @@ static unsigned int __read_mostly vm_end[VMAP_REGION_NR];/* lowest known clear bit in the bitmap */ static unsigned int vm_low[VMAP_REGION_NR ]; -mfn_t vmap_to_mfn (void *va) -{ -l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va)); -mfn_t ret =_mfn (l1e_get_pfn (*pl1e)); -unmap_xen_pagetable (pl1e); -return ret; -} - -struct page_info *vmap_to_page (void *va) -{ -return mfn_to_page (vmap_to_mfn (va)); -} -void __init vm_init_type (enum vmap_region type,void *start,void *end) {unsigned int i, nr;
@@ -332,7 +319,7 @@ void vfree(void *va)for ( i =0 ; i < pages; i++ ) { -struct page_info *page =vmap_to_page (va + i *PAGE_SIZE ); +struct page_info *page =virt_to_page_walk (va + i *PAGE_SIZE );ASSERT (page);page_list_add (page, &pg_list);
xen/include/asm-x86/mm.h +2 -0
@@ -643,6 +643,8 @@ void free_xen_pagetable(mfn_t mfn); }while (0 ) l1_pgentry_t *virt_to_xen_l1e(unsigned long v); +unsigned long virt_to_mfn_walk (void *va); +struct page_info *virt_to_page_walk (void *va);DECLARE_PER_CPU (mfn_t, root_pgt_mfn);
xen/include/xen/vmap.h +0 -3
@@ -23,9 +23,6 @@ void *vmalloc_xen(size_t size);void *vzalloc (size_t size);void vfree (void *va); -mfn_t vmap_to_mfn (void *va); -struct page_info *vmap_to_page (void *va); -void __iomem *ioremap (paddr_t ,size_t );static inline void iounmap (void __iomem *va)
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 73/84] x86/mm: Move vmap_to_mfn() to mm.c and rename to virt_to_mfn_walk().
Hi,
Quoted 6 lines · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Obviously,
vmap_to_mfnis a generic mechanism to walk the page table to find the mfn, not vmap specific. Also the difference fromvirt_to_mfn()is that it actually walks the page table instead of relying on a direct map.
vmap_to_mfn is the abstraction for common code. How this is implemented is arch dependent and therefore the name should stick like when call by common code.
For x86, you are free to alias vmap_to_mfn() to virt_to_mfn_walk(). It would also be good if you document in the code why a code would select virt_to_mfn_walk() and not virt_to_mfn().
Quoted 44 lines
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/mm.c | 13 +++++++++++++ xen/common/vmap.c | 15 +-------------- xen/include/asm-x86/mm.h | 2 ++ xen/include/xen/vmap.h | 3 --- 4 files changed, 16 insertions(+), 17 deletions(-)xen/arch/x86/mm.c +13
-0@@ -5056,6 +5056,19 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)return pl1e; } +unsigned long virt_to_mfn_walk (void *va) +{ +l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va)); +unsigned long ret =l1e_get_pfn (*pl1e); +unmap_xen_pagetable (pl1e); +return ret; +} + +struct page_info *virt_to_page_walk (void *va) +{ +return mfn_to_page (_mfn (virt_to_mfn_walk (va))); +} +/* Convert to from superpage-mapping flags for map_pages_to_xen(). */ #define l1f_to_lNf (f) (((f) & _PAGE_PRESENT) ? ((f) | _PAGE_PSE) : (f))#define lNf_to_l1f (f) (((f) & _PAGE_PRESENT) ? ((f) & ~_PAGE_PSE) : (f))xen/common/vmap.c +0
-3@@ -19,19 +19,6 @@ static unsigned int __read_mostly vm_end[VMAP_REGION_NR];/* lowest known clear bit in the bitmap */ static unsigned int vm_low[VMAP_REGION_NR ]; -mfn_t vmap_to_mfn (void *va) -{ -l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va));
xen/common/vmap.c static unsigned int __read_mostly vm_end[VMAP_REGION_NR]; · line 34
Quoted 10 lines
xen/common/vmap.c +0
-10-mfn_t ret =_mfn (l1e_get_pfn (*pl1e)); -unmap_xen_pagetable (pl1e); -return ret; -} - -struct page_info *vmap_to_page (void *va) -{ -return mfn_to_page (vmap_to_mfn (va)); -} -
Please avoid to add code in a patch that is move it later on. Instead you should put the code in the correct place from the beginning.
Quoted 31 lines
xen/common/vmap.c +1
-1void __init vm_init_type (enum vmap_region type,void *start,void *end) {unsigned int i, nr;@@ -332,7 +319,7 @@ void vfree(void *va)for ( i =0 ; i < pages; i++ ) { -struct page_info *page =vmap_to_page (va + i *PAGE_SIZE ); +struct page_info *page =virt_to_page_walk (va + i *PAGE_SIZE );ASSERT (page);page_list_add (page, &pg_list);xen/include/asm-x86/mm.h +2
-0@@ -643,6 +643,8 @@ void free_xen_pagetable(mfn_t mfn); }while (0 ) l1_pgentry_t *virt_to_xen_l1e(unsigned long v); +unsigned long virt_to_mfn_walk (void *va); +struct page_info *virt_to_page_walk (void *va);DECLARE_PER_CPU (mfn_t, root_pgt_mfn);xen/include/xen/vmap.h +0
-0
xen/include/xen/vmap.h void *vmalloc_xen(size_t size); · line 28
Quoted 9 lines
xen/include/xen/vmap.h +0
-3@@ -23,9 +23,6 @@ void *vmalloc_xen(size_t size);void *vzalloc (size_t size);void vfree (void *va); -mfn_t vmap_to_mfn (void *va); -struct page_info *vmap_to_page (void *va); -void __iomem *ioremap (paddr_t ,size_t );static inline void iounmap (void __iomem *va)
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 74/84 x86/pv: refactor how building dom0 in PV handles domheap mappings.
In reply to [email protected]From: Hongyan Xia <[email protected]>
Building a PV dom0 is allocating from the domheap but uses it like the xenheap. This is clearly wrong. Fix.
--- xen/arch/x86/pv/dom0_build.c | 40 ++++++++++++++++++++++++++---------- xen/include/asm-x86/mm.h | 1 + 2 files changed, 30 insertions(+), 11 deletions(-)
xen/arch/x86/pv/dom0_build.c +29 -11
@@ -623,7 +623,10 @@ int __init dom0_construct_pv(struct domain *d,if ( !is_pv_32bit_domain (d) ) {maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l4_page_table; - l4start = l4tab =__va (mpt_alloc); mpt_alloc +=PAGE_SIZE ; + l4start = l4tab =__va (mpt_alloc); +map_pages_to_xen ((unsigned long )l4start,maddr_to_mfn (mpt_alloc),1 , +PAGE_HYPERVISOR ); + mpt_alloc +=PAGE_SIZE ;clear_page (l4tab);init_xen_l4_slots (l4tab,_mfn (virt_to_mfn (l4start)), d,INVALID_MFN , true);
@@ -633,9 +636,12 @@ int __init dom0_construct_pv(struct domain *d, {/* Monitor table already created by switch_compat(). */ l4start = l4tab =__va (pagetable_get_paddr (v->arch.guest_table)); +map_pages_to_xen ((unsigned long )l4start, +pagetable_get_mfn (v->arch.guest_table),1 ,PAGE_HYPERVISOR );/* See public/xen.h on why the following is needed. */ maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l3_page_table; - l3start =__va (mpt_alloc); mpt_alloc +=PAGE_SIZE ; + l3start =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); + mpt_alloc +=PAGE_SIZE ; } l4tab +=l4_table_offset (v_start);
@@ -645,14 +651,18 @@ int __init dom0_construct_pv(struct domain *d,if ( !((unsigned long )l1tab & (PAGE_SIZE -1 )) ) {maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l1_page_table; - l1start = l1tab =__va (mpt_alloc); mpt_alloc +=PAGE_SIZE ; +UNMAP_XEN_PAGETABLE (l1start); + l1start = l1tab =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); + mpt_alloc +=PAGE_SIZE ;clear_page (l1tab);if ( count ==0 ) l1tab +=l1_table_offset (v_start);if ( !((unsigned long )l2tab & (PAGE_SIZE -1 )) ) {maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l2_page_table; - l2start = l2tab =__va (mpt_alloc); mpt_alloc +=PAGE_SIZE ; +UNMAP_XEN_PAGETABLE (l2start); + l2start = l2tab =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); + mpt_alloc +=PAGE_SIZE ;clear_page (l2tab);if ( count ==0 ) l2tab +=l2_table_offset (v_start);
@@ -662,19 +672,21 @@ int __init dom0_construct_pv(struct domain *d, {maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l3_page_table; - l3start =__va (mpt_alloc); mpt_alloc +=PAGE_SIZE ; +UNMAP_XEN_PAGETABLE (l3start); + l3start =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); + mpt_alloc +=PAGE_SIZE ; } l3tab = l3start;clear_page (l3tab);if ( count ==0 ) l3tab +=l3_table_offset (v_start); - *l4tab =l4e_from_paddr (__pa (l3start),L4_PROT ); + *l4tab =l4e_from_paddr (virt_to_maddr_walk (l3start),L4_PROT ); l4tab++; } - *l3tab =l3e_from_paddr (__pa (l2start),L3_PROT ); + *l3tab =l3e_from_paddr (virt_to_maddr_walk (l2start),L3_PROT ); l3tab++; } - *l2tab =l2e_from_paddr (__pa (l1start),L2_PROT ); + *l2tab =l2e_from_paddr (virt_to_maddr_walk (l1start),L2_PROT ); l2tab++; }if ( count < initrd_pfn || count >= initrd_pfn +PFN_UP (initrd_len) )
@@ -701,9 +713,11 @@ int __init dom0_construct_pv(struct domain *d,if ( !l3e_get_intpte (*l3tab) ) {maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l2_page_table; - l2tab =__va (mpt_alloc); mpt_alloc +=PAGE_SIZE ; -clear_page (l2tab); - *l3tab =l3e_from_paddr (__pa (l2tab),L3_PROT ); +UNMAP_XEN_PAGETABLE (l2start); + l2start =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); + mpt_alloc +=PAGE_SIZE ; +clear_page (l2start); + *l3tab =l3e_from_paddr (virt_to_maddr_walk (l2start),L3_PROT ); }if ( i ==3 )l3e_get_page (*l3tab)->u.inuse.type_info |= PGT_pae_xen_l2;
@@ -714,6 +728,10 @@ int __init dom0_construct_pv(struct domain *d,UNMAP_XEN_PAGETABLE (l2t); } +UNMAP_XEN_PAGETABLE (l1start); +UNMAP_XEN_PAGETABLE (l2start); +UNMAP_XEN_PAGETABLE (l3start); +/* Pages that are part of page tables must be read only. */ mark_pv_pt_pages_rdonly (d, l4start, vpt_start, nr_pt_pages);
xen/include/asm-x86/mm.h +1 -0
@@ -645,6 +645,7 @@ void free_xen_pagetable(mfn_t mfn);l1_pgentry_t *virt_to_xen_l1e (unsigned long v);unsigned long virt_to_mfn_walk (void *va);struct page_info *virt_to_page_walk (void *va); +#define virt_to_maddr_walk (va) mfn_to_maddr(_mfn(virt_to_mfn_walk(va)))DECLARE_PER_CPU (mfn_t, root_pgt_mfn);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 75/84 x86/mm: handle PSE early termination cases in virt_to_mfn_walk().
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/mm.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
xen/arch/x86/mm.c +34 -2
@@ -5058,8 +5058,40 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)unsigned long virt_to_mfn_walk (void *va) { -l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va)); -unsigned long ret =l1e_get_pfn (*pl1e); +unsigned long ret; +l3_pgentry_t *pl3e; +l2_pgentry_t *pl2e; +l1_pgentry_t *pl1e; + +/* +* FIXME: This is rather unoptimised, because e.g. virt_to_xen_l2e +* recomputes virt_to_xen_l3e again. Clearly one can keep the result and +* carry on. +*/ + + pl3e =virt_to_xen_l3e ((unsigned long )(va)); +BUG_ON (!(l3e_get_flags (*pl3e) & _PAGE_PRESENT)); +if (l3e_get_flags (*pl3e) & _PAGE_PSE ) + { + ret =l3e_get_pfn (*pl3e); + ret |= (((unsigned long )va & ((1UL <<L3_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); +unmap_xen_pagetable (pl3e); +return ret; + } + + pl2e =virt_to_xen_l2e ((unsigned long )(va)); +BUG_ON (!(l2e_get_flags (*pl2e) & _PAGE_PRESENT)); +if (l2e_get_flags (*pl2e) & _PAGE_PSE ) + { + ret =l2e_get_pfn (*pl2e); + ret |= (((unsigned long )va & ((1UL <<L2_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); +unmap_xen_pagetable (pl2e); +return ret; + } + + pl1e =virt_to_xen_l1e ((unsigned long )(va)); +BUG_ON (!(l1e_get_flags (*pl1e) & _PAGE_PRESENT)); + ret =l1e_get_pfn (*pl1e);unmap_xen_pagetable (pl1e);return ret; }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 75/84] x86/mm: handle PSE early termination cases in virt_to_mfn_walk().
Quoted 41 lines · On Thu, Sep 26, 2019 at 10:46:38AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/mm.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)xen/arch/x86/mm.c +24
-2@@ -5058,8 +5058,40 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)unsigned long virt_to_mfn_walk (void *va) { -l1_pgentry_t *pl1e =virt_to_xen_l1e ((unsigned long )(va)); -unsigned long ret =l1e_get_pfn (*pl1e); +unsigned long ret; +l3_pgentry_t *pl3e; +l2_pgentry_t *pl2e; +l1_pgentry_t *pl1e; + +/* +* FIXME: This is rather unoptimised, because e.g. virt_to_xen_l2e +* recomputes virt_to_xen_l3e again. Clearly one can keep the result and +* carry on. +*/ + + pl3e =virt_to_xen_l3e ((unsigned long )(va)); +BUG_ON (!(l3e_get_flags (*pl3e) & _PAGE_PRESENT)); +if (l3e_get_flags (*pl3e) & _PAGE_PSE ) + { + ret =l3e_get_pfn (*pl3e); + ret |= (((unsigned long )va & ((1UL <<L3_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); +unmap_xen_pagetable (pl3e); +return ret; + } + + pl2e =virt_to_xen_l2e ((unsigned long )(va)); +BUG_ON (!(l2e_get_flags (*pl2e) & _PAGE_PRESENT)); +if (l2e_get_flags (*pl2e) & _PAGE_PSE )
xen/arch/x86/mm.c l1_pgentry_t *virt_to_xen_l1e(unsigned long v) · line 5094
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+ { + ret =l2e_get_pfn (*pl2e); + ret |= (((unsigned long )va & ((1UL <<L2_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); +unmap_xen_pagetable (pl2e); +return ret; + } + + pl1e =virt_to_xen_l1e ((unsigned long )(va)); +BUG_ON (!(l1e_get_flags (*pl1e) & _PAGE_PRESENT)); + ret =l1e_get_pfn (*pl1e);
Don't you end up leaking pl3e and pl2e in the !PSE case?
Also, if you only want to walk page table that is already populated, there may be a better way to do it than calling virt_to_xen_lXe.
Wei.
Quoted 11 lines
xen/arch/x86/mm.c +0
-0unmap_xen_pagetable (pl1e);return ret; }Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 76/84 x86/setup: also clear the permission bits in the dummy 1:1 mapping.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/setup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/setup.c +2 -2
@@ -1368,7 +1368,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( map_e < end ) {map_pages_to_xen ((unsigned long )__va (map_e),INVALID_MFN , -PFN_DOWN (end - map_e),PAGE_HYPERVISOR ); +PFN_DOWN (end - map_e), _PAGE_NONE);init_boot_pages (map_e, end); map_e = end; }
@@ -1383,7 +1383,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( s < map_s ) {map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN , -PFN_DOWN (map_s - s),PAGE_HYPERVISOR ); +PFN_DOWN (map_s - s), _PAGE_NONE);init_boot_pages (s, map_s); } }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 76/84] x86/setup: also clear the permission bits in the dummy 1:1 mapping.
Quoted 2 lines · On Thu, Sep 26, 2019 at 10:46:39AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Assuming we end up keeping those calls, this patch should be squashed.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 77/84 x86: properly (un)map pages in restore_all_guests.
In reply to [email protected]From: Hongyan Xia <[email protected]>
Before, it assumed both cr3 could be accessed via a direct map. This is no longer true. Also, this means we can remove a xenheap mapping hack we introduced earlier when building the cr3 of dom0.
--- xen/arch/x86/pv/dom0_build.c | 11 +++++------ xen/arch/x86/x86_64/entry.S | 32 +++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 9 deletions(-)
xen/arch/x86/pv/dom0_build.c +5 -6
@@ -623,9 +623,7 @@ int __init dom0_construct_pv(struct domain *d,if ( !is_pv_32bit_domain (d) ) {maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l4_page_table; - l4start = l4tab =__va (mpt_alloc); -map_pages_to_xen ((unsigned long )l4start,maddr_to_mfn (mpt_alloc),1 , -PAGE_HYPERVISOR ); + l4start = l4tab =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); mpt_alloc +=PAGE_SIZE ;clear_page (l4tab); init_xen_l4_slots(l4tab, _mfn(virt_to_mfn(l4start)),
@@ -635,9 +633,8 @@ int __init dom0_construct_pv(struct domain *d,else {/* Monitor table already created by switch_compat(). */ - l4start = l4tab =__va (pagetable_get_paddr (v->arch.guest_table)); -map_pages_to_xen ((unsigned long )l4start, -pagetable_get_mfn (v->arch.guest_table),1 ,PAGE_HYPERVISOR ); + l4start = l4tab = +map_xen_pagetable (pagetable_get_mfn (v->arch.guest_table));/* See public/xen.h on why the following is needed. */ maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l3_page_table; l3start =map_xen_pagetable (maddr_to_mfn (mpt_alloc));
@@ -907,6 +904,8 @@ int __init dom0_construct_pv(struct domain *d,pv_shim_setup_dom (d, l4start, v_start, vxenstore_start, vconsole_start, vphysmap_start, si); +UNMAP_XEN_PAGETABLE (l4start); +if (is_pv_32bit_domain (d) )xlat_start_info (si, pv_shim ? XLAT_start_info_console_domU : XLAT_start_info_console_dom0);
xen/arch/x86/x86_64/entry.S +29 -3
@@ -150,11 +150,27 @@ restore_all_guest: je .Lrag_copy_done movb $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx) movabs $PADDR_MASK & PAGE_MASK, %rsi - movabs $DIRECTMAP_VIRT_START, %rcx and %rsi, %rdi and %r9, %rsi - add %rcx, %rdi - add %rcx, %rsi + + /* Without a direct map, we have to map pages first before copying. */ + /* FIXME: optimisations may be needed. */ + pushq %r9 + pushq %rdx + pushq %rax + pushq %rsi + shr $PAGE_SHIFT, %rdi + callq map_xen_pagetable + popq %rdi + pushq %rax + shr $PAGE_SHIFT, %rdi + callq map_xen_pagetable + mov %rax, %rsi + mov 0(%rsp), %rdi + + /* %rsi and %rdi are on top the stack for unmapping. */ + pushq %rsi + mov $ROOT_PAGETABLE_FIRST_XEN_SLOT, %ecx mov root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rsi), %r8 mov %r8, root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rdi)
@@ -166,6 +182,16 @@ restore_all_guest: sub $(ROOT_PAGETABLE_FIRST_XEN_SLOT - \ ROOT_PAGETABLE_LAST_XEN_SLOT - 1) * 8, %rdi rep movsq + + /* Unmap the two pages. */ + popq %rdi + callq unmap_xen_pagetable + popq %rdi + callq unmap_xen_pagetable + popq %rax + popq %rdx + popq %r9 + .Lrag_copy_done: mov %r9, STACK_CPUINFO_FIELD(xen_cr3)(%rdx) movb $1, STACK_CPUINFO_FIELD(use_pv_cr3)(%rdx)
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 77/84] x86: properly (un)map pages in restore_all_guests.
Quoted 40 lines · On Thu, Sep 26, 2019 at 10:46:40AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Before, it assumed both cr3 could be accessed via a direct map. This is no longer true. Also, this means we can remove a xenheap mapping hack we introduced earlier when building the cr3 of dom0.
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/pv/dom0_build.c | 11 +++++------ xen/arch/x86/x86_64/entry.S | 32 +++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 9 deletions(-)xen/arch/x86/pv/dom0_build.c +3
-6@@ -623,9 +623,7 @@ int __init dom0_construct_pv(struct domain *d,if ( !is_pv_32bit_domain (d) ) {maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l4_page_table; - l4start = l4tab =__va (mpt_alloc); -map_pages_to_xen ((unsigned long )l4start,maddr_to_mfn (mpt_alloc),1 , -PAGE_HYPERVISOR ); + l4start = l4tab =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); mpt_alloc +=PAGE_SIZE ;clear_page (l4tab); init_xen_l4_slots(l4tab, _mfn(virt_to_mfn(l4start)),@@ -635,9 +633,8 @@ int __init dom0_construct_pv(struct domain *d,else {/* Monitor table already created by switch_compat(). */ - l4start = l4tab =__va (pagetable_get_paddr (v->arch.guest_table)); -map_pages_to_xen ((unsigned long )l4start, -pagetable_get_mfn (v->arch.guest_table),1 ,PAGE_HYPERVISOR ); + l4start = l4tab = +map_xen_pagetable (pagetable_get_mfn (v->arch.guest_table));/* See public/xen.h on why the following is needed. */ maddr_to_page (mpt_alloc)->u.inuse.type_info = PGT_l3_page_table; l3start =map_xen_pagetable (maddr_to_mfn (mpt_alloc));
xen/arch/x86/pv/dom0_build.c int __init dom0_construct_pv(struct domain *d, · line 908
Quoted 5 lines
xen/arch/x86/pv/dom0_build.c +2
-0@@ -907,6 +904,8 @@ int __init dom0_construct_pv(struct domain *d,pv_shim_setup_dom (d, l4start, v_start, vxenstore_start, vconsole_start, vphysmap_start, si); +UNMAP_XEN_PAGETABLE (l4start); +
These hunks should be part of a previous patch, right? The one you changed PV Dom0 construction.
Quoted 42 lines
xen/arch/x86/pv/dom0_build.c +0
-0if (is_pv_32bit_domain (d) )xlat_start_info (si, pv_shim ? XLAT_start_info_console_domU : XLAT_start_info_console_dom0);xen/arch/x86/x86_64/entry.S +19
-3@@ -150,11 +150,27 @@ restore_all_guest: je .Lrag_copy_done movb $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx) movabs $PADDR_MASK & PAGE_MASK, %rsi - movabs $DIRECTMAP_VIRT_START, %rcx and %rsi, %rdi and %r9, %rsi - add %rcx, %rdi - add %rcx, %rsi + + /* Without a direct map, we have to map pages first before copying. */ + /* FIXME: optimisations may be needed. */ + pushq %r9 + pushq %rdx + pushq %rax + pushq %rsi + shr $PAGE_SHIFT, %rdi + callq map_xen_pagetable + popq %rdi + pushq %rax + shr $PAGE_SHIFT, %rdi + callq map_xen_pagetable + mov %rax, %rsi + mov 0(%rsp), %rdi + + /* %rsi and %rdi are on top the stack for unmapping. */ + pushq %rsi + mov $ROOT_PAGETABLE_FIRST_XEN_SLOT, %ecx mov root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rsi), %r8 mov %r8, root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rdi)@@ -166,6 +182,16 @@ restore_all_guest: sub $(ROOT_PAGETABLE_FIRST_XEN_SLOT - \ ROOT_PAGETABLE_LAST_XEN_SLOT - 1) * 8, %rdi rep movsq
xen/arch/x86/x86_64/entry.S restore_all_guest: · line 194
Quoted 10 lines
xen/arch/x86/x86_64/entry.S +10
-0+ + /* Unmap the two pages. */ + popq %rdi + callq unmap_xen_pagetable + popq %rdi + callq unmap_xen_pagetable + popq %rax + popq %rdx + popq %r9 +
This section is for synchronising root page tables. Now that it has become so long, it would be better if you write a C function for this purpose.
Wei.
Quoted 6 lines
xen/arch/x86/x86_64/entry.S +0
-0.Lrag_copy_done: mov %r9, STACK_CPUINFO_FIELD(xen_cr3)(%rdx) movb $1, STACK_CPUINFO_FIELD(use_pv_cr3)(%rdx)Signature · 1 line
2.17.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 78/84 Revert "x86/smpboot: use xenheap pages for rpts in smpboot."
In reply to [email protected]From: Hongyan Xia <[email protected]>
We have properly handled (un)mapping of pages in restore_all_guests. This hack is no longer required.
--- xen/arch/x86/smpboot.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
xen/arch/x86/smpboot.c +7 -12
@@ -832,20 +832,14 @@ static int setup_cpu_root_pgt(unsigned int cpu) goto out; } -/* -* Unfortunately, some code (especially in assembly) assumes the rpt is in -* the DIRECTMAP region and is always mapped. Making all of them adapt to -* the new page table APIs is non-trivial. For now, make it always mapped -* on the xenheap. -*/ - rpt =alloc_xenheap_page (); -if ( !rpt ) + rpt_mfn =alloc_xen_pagetable (); +if (mfn_eq (rpt_mfn,INVALID_MFN ) ) { rc = -ENOMEM ; goto out; } - rpt_mfn =_mfn (virt_to_mfn (rpt)); + rpt =map_xen_pagetable (rpt_mfn);clear_page (rpt);per_cpu (root_pgt_mfn, cpu) = rpt_mfn;
@@ -890,6 +884,7 @@ static int setup_cpu_root_pgt(unsigned int cpu) rc =clone_mapping ((void *)per_cpu (stubs.addr, cpu), rpt); out: +UNMAP_XEN_PAGETABLE (rpt);return rc; }
@@ -905,7 +900,7 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)per_cpu (root_pgt_mfn, cpu) =INVALID_MFN ; - rpt =mfn_to_virt (mfn_x (rpt_mfn)); + rpt =map_xen_pagetable (rpt_mfn);for ( r =root_table_offset (DIRECTMAP_VIRT_START ); r <root_table_offset (HYPERVISOR_VIRT_END ); ++r )
@@ -950,8 +945,8 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)free_xen_pagetable (l3t_mfn); } -/* Unlike other levels, the root level is a xenheap page. */ -free_xenheap_page (rpt); +UNMAP_XEN_PAGETABLE (rpt); +free_xen_pagetable (rpt_mfn);/* Also zap the stub mapping for this CPU. */ if ( stub_linear )
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 78/84] Revert "x86/smpboot: use xenheap pages for rpts in smpboot."
Quoted 6 lines · On Thu, Sep 26, 2019 at 10:46:41AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
We have properly handled (un)mapping of pages in
restore_all_guests. This hack is no longer required.Signed-off-by Hongyan Xia <[email protected]>
If you rearrange this series a bit you don't need this and the patch it reverts in the first place, I think.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 79/84 Don't assume bootmem_region_list is mapped. Also fix a double unmap bug.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/pv/dom0_build.c | 2 +- xen/common/page_alloc.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/pv/dom0_build.c +1 -1
@@ -236,7 +236,7 @@ static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn,if ( pl3e )unmap_domain_page (pl3e); -unmap_domain_page (l4start); +//unmap_domain_page(l4start); } static struct page_info * __init alloc_chunk(struct domain *d,
xen/common/page_alloc.c +10 -2
@@ -247,6 +247,7 @@ mfn_t first_valid_mfn = INVALID_MFN_INITIALIZER;static struct bootmem_region {unsigned long s, e;/* MFNs @s through @e-1 inclusive are free */ } *__initdata bootmem_region_list; +struct page_info *bootmem_region_list_pg;static unsigned int __initdata nr_bootmem_regions;struct scrub_region {
@@ -264,7 +265,11 @@ static void __init bootmem_region_add(unsigned long s, unsigned long e)unsigned int i;if ( (bootmem_region_list ==NULL ) && (s < e) ) - bootmem_region_list =mfn_to_virt (s++); + { + bootmem_region_list_pg =mfn_to_page (_mfn (s)); + bootmem_region_list =map_domain_page (_mfn (s)); + s++; + }if ( s >= e )return ;
@@ -1869,7 +1874,10 @@ void __init end_boot_allocator(void)init_heap_pages (mfn_to_page (_mfn (r->s)), r->e - r->s); } nr_bootmem_regions =0 ; -init_heap_pages (virt_to_page (bootmem_region_list),1 ); +init_heap_pages (bootmem_region_list_pg,1 ); +/* Remember to discard the mapping for bootmem_region_list. */ +unmap_domain_page (bootmem_region_list); +flush_tlb_one_local (bootmem_region_list);if ( !dma_bitsize && (num_online_nodes () >1 ) ) dma_bitsize =arch_get_dma_bitsize ();
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 79/84] Don't assume bootmem_region_list is mapped. Also fix a double unmap bug.
Hi,
From the title, this patch is doing two things:
1) Map bootmem_region_list
2) Fix double unmap bug
It is not entirely clear how the latter is related to the former. Can you explain it?
Quoted 1 line · On 9/26/19 10:46 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Please provide a commit message description.
Quoted 12 lines
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/pv/dom0_build.c | 2 +- xen/common/page_alloc.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-)xen/arch/x86/pv/dom0_build.c +0
-0
xen/arch/x86/pv/dom0_build.c static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn, · line 239
Quoted 5 lines
xen/arch/x86/pv/dom0_build.c +1
-1@@ -236,7 +236,7 @@ static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn,if ( pl3e )unmap_domain_page (pl3e); -unmap_domain_page (l4start); +//unmap_domain_page(l4start);
I guess you wanted to remove it completely and not comment it?
xen/common/page_alloc.c mfn_t first_valid_mfn = INVALID_MFN_INITIALIZER; · line 250
Quoted 12 lines
xen/arch/x86/pv/dom0_build.c +0
-0} static struct page_info * __init alloc_chunk(struct domain *d,xen/common/page_alloc.c +1
-0@@ -247,6 +247,7 @@ mfn_t first_valid_mfn = INVALID_MFN_INITIALIZER;static struct bootmem_region {unsigned long s, e;/* MFNs @s through @e-1 inclusive are free */ } *__initdata bootmem_region_list; +struct page_info *bootmem_region_list_pg;
I guess this should be static. But...
xen/common/page_alloc.c static void __init bootmem_region_add(unsigned long s, unsigned long e) · line 269
Quoted 10 lines
xen/common/page_alloc.c +2
-1static unsigned int __initdata nr_bootmem_regions;struct scrub_region {@@ -264,7 +265,11 @@ static void __init bootmem_region_add(unsigned long s, unsigned long e)unsigned int i;if ( (bootmem_region_list ==NULL ) && (s < e) ) - bootmem_region_list =mfn_to_virt (s++); + { + bootmem_region_list_pg =mfn_to_page (_mfn (s));
... at least on Arm, the frametable is allocated after the boot allocator has been initialized. So mfn_to_page() will not work properly here.
xen/common/page_alloc.c static void __init bootmem_region_add(unsigned long s, unsigned long e) · line 270
Quoted 1 line
xen/common/page_alloc.c +1
-0+ bootmem_region_list =map_domain_page (_mfn (s));
So I would suggest to look at statically allocating the bootmem_region_list. This was actually discussed recently as part of on-going problem with Arm32 (see [1]).
I am planning to have a look after I finish some important bug fixes for Xen 4.13. But feel free to have a look.
Quoted 8 lines
xen/common/page_alloc.c +2
-0+ s++; + }if ( s >= e )return ;@@ -1869,7 +1874,10 @@ void __init end_boot_allocator(void)init_heap_pages (mfn_to_page (_mfn (r->s)), r->e - r->s);
xen/common/page_alloc.c void __init end_boot_allocator(void) · line 1883
Quoted 10 lines
xen/common/page_alloc.c +4
-1} nr_bootmem_regions =0 ; -init_heap_pages (virt_to_page (bootmem_region_list),1 ); +init_heap_pages (bootmem_region_list_pg,1 ); +/* Remember to discard the mapping for bootmem_region_list. */ +unmap_domain_page (bootmem_region_list); +flush_tlb_one_local (bootmem_region_list);if ( !dma_bitsize && (num_online_nodes () >1 ) ) dma_bitsize =arch_get_dma_bitsize ();
Cheers,
[1] https://lists.xen.org/archives/html/xen-devel/2019-09/msg01407.html
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 79/84] Don't assume bootmem_region_list is mapped. Also fix a double unmap bug.
Quoted 7 lines · Julien Grall
Hi,
From the title, this patch is doing two things:
1) Mapbootmem_region_list
2) Fix double unmap bugIt is not entirely clear how the latter is related to the former. Can you explain it?
Actually they are not related. The second one should probably be squashed into some other patch.
Quoted 6 lines · On 9/26/19 10:46 AM, [email protected] wrote:
Quoted 1 line
From: Hongyan Xia <[email protected]>
Please provide a commit message description.
The description is just a one-liner in the subject. Should be there when you import this patch.
Quoted 7 lines
Quoted 7 lines
Signed-off-by Hongyan Xia <[email protected]>---
xen/arch/x86/pv/dom0_build.c| 2 +-
xen/common/page_alloc.c | 12 ++++++++++--2 files changed, 11 insertions(+), 3 deletions(-)
Quoted 13 lines
xen/arch/x86/pv/dom0_build.c static __init void setup_pv_physmap(struct domain *d, · line 239
Quoted 10 lines
xen/arch/x86/pv/dom0_build.c +1
-1@@ -236,7 +236,7 @@ static __init void setup_pv_physmap(struct domain *d,unsigned long pgtbl_pfn, if ( pl3e ) unmap_domain_page(pl3e); - unmap_domain_page(l4start); + //unmap_domain_page(l4start);I guess you wanted to remove it completely and not comment it?
Thanks. Will fix.
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/pv/dom0_build.c +0
-0} static struct page_info * __init alloc_chunk(struct domain *d,xen/common/page_alloc.c +0
-1--- a/xen/common/page_alloc.c
Quoted 9 lines
Quoted 6 lines
+++
b/xen/common/page_alloc.cxen/common/page_alloc.c +0
-0@@ -247,6 +247,7 @@ mfn_t first_valid_mfn = INVALID_MFN_INITIALIZER; static struct bootmem_region {unsigned long s, e; /* MFNs @s through @e-1 inclusive are free */ }
*__initdatabootmem_region_list;
+structpage_info*bootmem_region_list_pg;I guess this should be static. But...
Yes.
Quoted 12 lines
xen/common/page_alloc.c static void __init bootmem_region_add(unsigned long s, · line 269
Quoted 9 lines
static unsigned int
__initdatanr_bootmem_regions; structscrub_region{xen/common/page_alloc.c +2
-1@@ -264,7 +265,11 @@ static void __init bootmem_region_add(unsigned long s, unsigned long e) unsigned int i; if ( (bootmem_region_list == NULL) && (s < e) ) - bootmem_region_list = mfn_to_virt(s++); + { + bootmem_region_list_pg = mfn_to_page(_mfn(s));... at least on Arm, the frametable is allocated after the boot allocator has been initialized. So
mfn_to_page()will not work properly here.
It works because the bootmem_region_list_pg is only accessed later in end_boot_allocator() when the frametable has been initialised. This pg is just to remember what the pg will be when the frametable is ready. Of course, to avoid confusion, I could keep the bootmem_region_list_mfn and only convert to pg later in end_boot_allocator().
Quoted 4 lines
xen/common/page_alloc.c static void __init bootmem_region_add(unsigned long s, unsigned long e) · line 270
Quoted 1 line
xen/common/page_alloc.c +1
-0+ bootmem_region_list = map_domain_page(_mfn(s));So I would suggest to look at statically allocating the
bootmem_region_list. This was actually discussed recently as part of on-going problem with Arm32 (see [1]).
Actually this patch series introduces PMAP infrastructure for x86, so this map_domain_page() works. It certainly won't work for ARM though without also introducing PMAP.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 79/84] Don't assume bootmem_region_list is mapped. Also fix a double unmap bug.
Hi,
Quoted 12 lines · On 9/26/19 1:36 PM, [email protected] wrote:
Quoted 7 lines · Julien Grall
Hi,
From the title, this patch is doing two things:
1) Mapbootmem_region_list
2) Fix double unmap bugIt is not entirely clear how the latter is related to the former. Can you explain it?
Actually they are not related. The second one should probably be squashed into some other patch.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines · On 9/26/19 10:46 AM, [email protected] wrote:
Quoted 1 line
From: Hongyan Xia <[email protected]>
Please provide a commit message description.
The description is just a one-liner in the subject. Should be there when you import this patch.
I am afraid this is not enough to understand the patch. You should explain in the patch you need it...
Quoted 54 lines
Quoted 8 lines
Quoted 8 lines
Signed-off-by Hongyan Xia <[email protected]>---
xen/arch/x86/pv/dom0_build.c| 2 +-
xen/common/page_alloc.c | 12 ++++++++++--2 files changed, 11 insertions(+), 3 deletions(-)Quoted 13 lines
xen/arch/x86/pv/dom0_build.c static __init void setup_pv_physmap(struct domain · line 239
Quoted 10 lines
xen/arch/x86/pv/dom0_build.c +1
-1@@ -236,7 +236,7 @@ static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn, if ( pl3e ) unmap_domain_page(pl3e); - unmap_domain_page(l4start); + //unmap_domain_page(l4start);I guess you wanted to remove it completely and not comment it?
Thanks. Will fix.
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/pv/dom0_build.c +0
-0} static struct page_info * __init alloc_chunk(struct domain *d,xen/common/page_alloc.c +0
-1--- a/xen/common/page_alloc.cQuoted 9 lines
Quoted 6 lines
+++
b/xen/common/page_alloc.cxen/common/page_alloc.c +0
-0@@ -247,6 +247,7 @@ mfn_t first_valid_mfn = INVALID_MFN_INITIALIZER; static struct bootmem_region {unsigned long s, e; /* MFNs @s through @e-1 inclusive are free */ }
*__initdatabootmem_region_list;
+structpage_info*bootmem_region_list_pg;I guess this should be static. But...
Yes.
Quoted 12 lines
xen/common/page_alloc.c static void __init bootmem_region_add(unsigned · line 269
Quoted 9 lines
static unsigned int
__initdatanr_bootmem_regions; structscrub_region{xen/common/page_alloc.c +2
-1@@ -264,7 +265,11 @@ static void __init bootmem_region_add(unsigned long s, unsigned long e) unsigned int i; if ( (bootmem_region_list == NULL) && (s < e) ) - bootmem_region_list = mfn_to_virt(s++); + { + bootmem_region_list_pg = mfn_to_page(_mfn(s));... at least on Arm, the frametable is allocated after the boot allocator has been initialized. So
mfn_to_page()will not work properly here.
Quoted 1 line
It works because the
bootmem_region_list_pgis only accessed later inend_boot_allocator()when the frametable has been initialised. This pg is just to remember what the pg will be when the frametable is ready. Of course, to avoid confusion, I could keep thebootmem_region_list_mfnand only convert to pg later inend_boot_allocator().
This only works because mfn_to_page() does not depend on anything initialized afterwards for x86. This is not true on Arm because the helper depends on frametable_base_pdx which is not initialized until setup_frametable_mappings() is called.
So you will have the wrong pointer to the page.
Quoted 7 lines
.
Quoted 4 lines
xen/common/page_alloc.c static void __init bootmem_region_add(unsigned long s, unsigned long e) · line 270
Quoted 1 line
xen/common/page_alloc.c +1
-0+ bootmem_region_list = map_domain_page(_mfn(s));So I would suggest to look at statically allocating the
bootmem_region_list. This was actually discussed recently as part of on-going problem with Arm32 (see [1]).Actually this patch series introduces PMAP infrastructure for x86, so this
map_domain_page()works. It certainly won't work for ARM though without also introducing PMAP.
Well, map_domain_page() is meant to be used for domain heap page.
At the moment, the boot allocator requires a xenheap page on the first call. So IHMO, you are be misusing the function.
Hence, I strongly think the static allocation is the best here.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 80/84 x86/setup: Install dummy 1:1 mappings for all mem passed to allocators.
In reply to [email protected]From: Hongyan Xia <[email protected]>
This means we no longer have an always-mapped direct map now.
--- xen/arch/x86/setup.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/setup.c +11 -3
@@ -240,7 +240,9 @@ void __init discard_initial_images(void)uint64_t start = (uint64_t )initial_images[i].mod_start <<PAGE_SHIFT ;init_domheap_pages (start, - start +PAGE_ALIGN (initial_images[i].mod_end)); + start +PAGE_ALIGN (initial_images[i].mod_end)); +map_pages_to_xen ((unsigned long )__va (start),INVALID_MFN , +PFN_DOWN (PAGE_ALIGN (initial_images[i].mod_end)), _PAGE_NONE); } nr_initial_images =0 ;
@@ -1346,6 +1348,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Pass mapped memory to allocator /before/ creating new mappings. */ init_boot_pages (s,min (map_s, e)); +map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN , +PFN_DOWN (min (map_s, e) - s), _PAGE_NONE); s = map_s;if ( s < map_e ) {
@@ -1354,6 +1358,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) map_s = (s + mask) & ~mask; map_e &= ~mask;init_boot_pages (map_s, map_e); +map_pages_to_xen ((unsigned long )__va (map_s),INVALID_MFN , +PFN_DOWN (map_e - map_s), _PAGE_NONE); }if ( map_s > map_e )
@@ -1367,9 +1373,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( map_e < end ) { +init_boot_pages (map_e, end);map_pages_to_xen ((unsigned long )__va (map_e),INVALID_MFN ,PFN_DOWN (end - map_e), _PAGE_NONE); -init_boot_pages (map_e, end); map_e = end; } }
@@ -1382,9 +1388,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) }if ( s < map_s ) { +init_boot_pages (s, map_s);map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN ,PFN_DOWN (map_s - s), _PAGE_NONE); -init_boot_pages (s, map_s); } }
@@ -1506,6 +1512,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)if (PFN_DOWN (s) <= limit ) s =pfn_to_paddr (limit +1 );init_domheap_pages (s, e); +map_pages_to_xen ((unsigned long )__va (s),INVALID_MFN , +PFN_DOWN (e - s), _PAGE_NONE); } }else
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 80/84] x86/setup: Install dummy 1:1 mappings for all mem passed to allocators.
Quoted 3 lines · On Thu, Sep 26, 2019 at 10:46:43AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
This means we no longer have an always-mapped direct map now.
But why a dummy mapping is this needed at all? That's the same question that was asked in a previous patch.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 81/84 x86/mm: optimise and properly unmap pages in virt_to_mfn_walk().
In reply to [email protected]From: Hongyan Xia <[email protected]>
This also resolves a mapcache overflow bug.
--- xen/arch/x86/mm.c | 57 +++++++++++++++++++++++++--------------- xen/include/asm-x86/mm.h | 3 ++- 2 files changed, 38 insertions(+), 22 deletions(-)
xen/arch/x86/mm.c +36 -21
@@ -5056,42 +5056,57 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)return pl1e; } +/* +* Unlike virt_to_mfn() which just translates between the direct map and the +* mfn, this version actually walks the page table to find the mfn of any +* virtual address, as long as it is mapped. If not, INVALID_MFN is returned. +*/ unsigned long virt_to_mfn_walk (void *va) {unsigned long ret; -l3_pgentry_t *pl3e; -l2_pgentry_t *pl2e; -l1_pgentry_t *pl1e; - -/* -* FIXME: This is rather unoptimised, because e.g. virt_to_xen_l2e -* recomputes virt_to_xen_l3e again. Clearly one can keep the result and -* carry on. -*/ +unsigned long v = (unsigned long )va; +l3_pgentry_t *pl3e =NULL ; +l2_pgentry_t *pl2e =NULL ; +l1_pgentry_t *pl1e =NULL ; - pl3e =virt_to_xen_l3e ((unsigned long )(va)); -BUG_ON (!(l3e_get_flags (*pl3e) & _PAGE_PRESENT)); + pl3e =virt_to_xen_l3e (v); +if ( !pl3e || !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) ) + { + ret =mfn_x (INVALID_MFN ); + goto out; + }if (l3e_get_flags (*pl3e) & _PAGE_PSE ) { ret =l3e_get_pfn (*pl3e); - ret |= (((unsigned long )va & ((1UL <<L3_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); -unmap_xen_pagetable (pl3e); -return ret; + ret |= ((v & ((1UL <<L3_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); + goto out; } - pl2e =virt_to_xen_l2e ((unsigned long )(va)); -BUG_ON (!(l2e_get_flags (*pl2e) & _PAGE_PRESENT)); + pl2e = (l2_pgentry_t *)map_xen_pagetable (l3e_get_mfn (*pl3e)) + +l2_table_offset (v); +if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) + { + ret =mfn_x (INVALID_MFN ); + goto out; + }if (l2e_get_flags (*pl2e) & _PAGE_PSE ) { ret =l2e_get_pfn (*pl2e); - ret |= (((unsigned long )va & ((1UL <<L2_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); -unmap_xen_pagetable (pl2e); -return ret; + ret |= ((v & ((1UL <<L2_PAGETABLE_SHIFT )-1 )) >>PAGE_SHIFT ); + goto out; } - pl1e =virt_to_xen_l1e ((unsigned long )(va)); -BUG_ON (!(l1e_get_flags (*pl1e) & _PAGE_PRESENT)); + pl1e = (l1_pgentry_t *)map_xen_pagetable (l2e_get_mfn (*pl2e)) + +l1_table_offset (v); +if ( !(l1e_get_flags (*pl1e) & _PAGE_PRESENT) ) + { + ret =mfn_x (INVALID_MFN ); + goto out; + } ret =l1e_get_pfn (*pl1e); +out: +unmap_xen_pagetable (pl3e); +unmap_xen_pagetable (pl2e);unmap_xen_pagetable (pl1e);return ret; }
xen/include/asm-x86/mm.h +2 -1
@@ -645,7 +645,8 @@ void free_xen_pagetable(mfn_t mfn);l1_pgentry_t *virt_to_xen_l1e (unsigned long v);unsigned long virt_to_mfn_walk (void *va);struct page_info *virt_to_page_walk (void *va); -#define virt_to_maddr_walk (va) mfn_to_maddr(_mfn(virt_to_mfn_walk(va))) +#define virt_to_maddr_walk (va) (mfn_to_maddr(_mfn(virt_to_mfn_walk(va))) | \ + ((unsigned long)va & (PAGE_SIZE - 1)))DECLARE_PER_CPU (mfn_t, root_pgt_mfn);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 81/84] x86/mm: optimise and properly unmap pages in virt_to_mfn_walk().
Quoted 3 lines · On Thu, Sep 26, 2019 at 10:46:44AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
This also resolves a mapcache overflow bug.
This should be squashed into the patch that touched virt_to_mfn_walk.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 82/84 x86: deduplicate code a bit and fix an unmapping bug.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/domain_page.c | 28 +++++++++++----------------- xen/arch/x86/pv/dom0_build.c | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-)
xen/arch/x86/domain_page.c +11 -17
@@ -77,29 +77,16 @@ void *map_domain_page(mfn_t mfn)struct mapcache_domain *dcache;struct mapcache_vcpu *vcache;struct vcpu_maphash_entry *hashent; +void *ret; v =mapcache_current_vcpu ();if ( !v ) - { -void *ret; -pmap_lock (); - ret =pmap_map (mfn); -pmap_unlock (); -flush_tlb_one_local (ret); -return ret; - } + goto pmap; dcache = &v->domain->arch.mapcache; vcache = &v->arch.mapcache;if ( !dcache->inuse ) - { -void *ret; -pmap_lock (); - ret =pmap_map (mfn); -pmap_unlock (); -flush_tlb_one_local (ret); -return ret; - } + goto pmap;perfc_incr (map_domain_page_count);
@@ -179,9 +166,16 @@ void *map_domain_page(mfn_t mfn)l1e_write (&MAPCACHE_L1ENT (idx),l1e_from_mfn (mfn, __PAGE_HYPERVISOR_RW)); - out: +out:local_irq_restore (flags);return (void *)MAPCACHE_VIRT_START +pfn_to_paddr (idx); + +pmap: +pmap_lock (); + ret =pmap_map (mfn); +pmap_unlock (); +flush_tlb_one_local (ret); +return ret; }void unmap_domain_page (const void *ptr)
xen/arch/x86/pv/dom0_build.c +1 -1
@@ -236,7 +236,7 @@ static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn,if ( pl3e )unmap_domain_page (pl3e); -//unmap_domain_page(l4start); +unmap_domain_page (l4start); } static struct page_info * __init alloc_chunk(struct domain *d,
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 82/84] x86: deduplicate code a bit and fix an unmapping bug.
xen/arch/x86/pv/dom0_build.c static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn, · line 239
Quoted 12 lines · On Thu, Sep 26, 2019 at 10:46:45AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
voidunmap_domain_page(const void *ptr)xen/arch/x86/pv/dom0_build.c +1
-1@@ -236,7 +236,7 @@ static __init void setup_pv_physmap(struct domain *d, unsigned long pgtbl_pfn,if ( pl3e )unmap_domain_page (pl3e); -//unmap_domain_page(l4start); +unmap_domain_page (l4start);
Please fix the bug where it was introduced.
Wei.
Quoted 6 lines
xen/arch/x86/pv/dom0_build.c +0
-0} static struct page_info * __init alloc_chunk(struct domain *d,Signature · 1 line
2.17.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 83/84 x86/pmap: rewrite logic for locking.
In reply to [email protected]From: Hongyan Xia <[email protected]>
Due to the limited PMAP entries, another pCPU is allowed to use PMAP only when the current pCPU has unmapped all mappings.
--- xen/arch/x86/domain_page.c | 4 ---- xen/arch/x86/pmap.c | 48 ++++++++++++++++++++++++++++++++------ xen/include/asm-x86/pmap.h | 2 -- 3 files changed, 41 insertions(+), 13 deletions(-)
xen/arch/x86/domain_page.c +0 -4
@@ -171,9 +171,7 @@ out:return (void *)MAPCACHE_VIRT_START +pfn_to_paddr (idx); pmap: -pmap_lock (); ret =pmap_map (mfn); -pmap_unlock ();flush_tlb_one_local (ret);return ret; }
@@ -188,9 +186,7 @@ void unmap_domain_page(const void *ptr)if ( va >=FIXADDR_START && va <FIXADDR_TOP ) { -pmap_lock ();pmap_unmap ((void *)ptr); -pmap_unlock ();return ; }
xen/arch/x86/pmap.c +41 -7
79 lines not on this page · raw message
xen/include/asm-x86/pmap.h +0 -2
@@ -4,8 +4,6 @@/* Large enough for mapping 5 levels of page tables with some headroom */ #define NUM_FIX_PMAP 8 -void pmap_lock (void ); -void pmap_unlock (void );void *pmap_map (mfn_t mfn);void pmap_unmap (void *p);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 83/84] x86/pmap: rewrite logic for locking.
Quoted 5 lines · On Thu, Sep 26, 2019 at 10:46:46AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Due to the limited PMAP entries, another pCPU is allowed to use PMAP only when the current pCPU has unmapped all mappings.
Under what condition would two pCPUs try to use PMAP at the same time?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 84/84 x86/pv: fix a couple of direct map assumptions in dom0 building.
In reply to [email protected]From: Hongyan Xia <[email protected]>
--- xen/arch/x86/pv/dom0_build.c | 7 ++++--- xen/include/asm-x86/processor.h | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-)
xen/arch/x86/pv/dom0_build.c +4 -3
@@ -626,9 +626,10 @@ int __init dom0_construct_pv(struct domain *d, l4start = l4tab =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); mpt_alloc +=PAGE_SIZE ;clear_page (l4tab); -init_xen_l4_slots (l4tab,_mfn (virt_to_mfn (l4start)), - d,INVALID_MFN , true); - v->arch.guest_table =pagetable_from_paddr (__pa (l4start)); +init_xen_l4_slots (l4tab,_mfn (virt_to_mfn_walk (l4start)), d, +INVALID_MFN , true); + v->arch.guest_table = +pagetable_from_mfn (_mfn (virt_to_mfn_walk (l4start))); }else {
xen/include/asm-x86/processor.h +0 -2
@@ -465,8 +465,6 @@ static inline void disable_each_ist(idt_entry_t *idt)extern idt_entry_t idt_table[];extern idt_entry_t *idt_tables[]; -DECLARE_PER_CPU(struct tss_struct, init_tss); -extern void write_ptbase (struct vcpu *v);/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 84/84] x86/pv: fix a couple of direct map assumptions in dom0 building.
Quoted 31 lines · On Thu, Sep 26, 2019 at 10:46:47AM +0100, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Signed-off-by Hongyan Xia <[email protected]>--- xen/arch/x86/pv/dom0_build.c | 7 ++++--- xen/include/asm-x86/processor.h | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-)xen/arch/x86/pv/dom0_build.c +4
-3@@ -626,9 +626,10 @@ int __init dom0_construct_pv(struct domain *d, l4start = l4tab =map_xen_pagetable (maddr_to_mfn (mpt_alloc)); mpt_alloc +=PAGE_SIZE ;clear_page (l4tab); -init_xen_l4_slots (l4tab,_mfn (virt_to_mfn (l4start)), - d,INVALID_MFN , true); - v->arch.guest_table =pagetable_from_paddr (__pa (l4start)); +init_xen_l4_slots (l4tab,_mfn (virt_to_mfn_walk (l4start)), d, +INVALID_MFN , true); + v->arch.guest_table = +pagetable_from_mfn (_mfn (virt_to_mfn_walk (l4start))); }else {xen/include/asm-x86/processor.h +0
-0
xen/include/asm-x86/processor.h static inline void disable_each_ist(idt_entry_t *idt) · line 469
Quoted 5 lines
xen/include/asm-x86/processor.h +0
-2@@ -465,8 +465,6 @@ static inline void disable_each_ist(idt_entry_t *idt)extern idt_entry_t idt_table[];extern idt_entry_t *idt_tables[]; -DECLARE_PER_CPU(struct tss_struct, init_tss); -
Why is this deleted?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Thank you for posting the series.
Quoted 8 lines · On 9/26/19 10:45 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Previously, Wei Liu has created the patch series to switch to alloc/map/unmap/free APIs for Xen page tables so that Xen page tables are mapped with
map_domain_page(). This is the first step towards removing the direct map. I implemented patches on top of Wei's to remove the direct map completely.
Quoted 9 lines
In addition to Wei's, my patches:
- (Wei) implement a proper PMAP infrastructure for bootstrapping
- remove direct map code inmap_domain_page()and use mapcache, use PMAP when mapcache not ready
- map/unmap xenheap allocations to the direct map region so that va<->pa macros still work
- install dummy mappings (no permissions,INVALID_MFN) instead of actual 1:1 mappings during boot, so the direct map no longer exists
- fix many places where code incorrectly assumes a direct map
I am a bit confused. Are your patches fixing bug from Wei's series?
Quoted 5 lines
I have moderately tested the patches. I am able to boot into dom0, create/destroy PV/HVM guests and run XTF tests. Personally, I find it difficult to discover all places where it incorrectly assumes a direct map, so reviews and further testing are more than welcome.
Do you have a branch with this series applied?
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 23 lines · Julien Grall
Hi,
Thank you for posting the series.
Quoted 8 lines · On 9/26/19 10:45 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Previously, Wei Liu has created the patch series to switch to alloc/map/unmap/free APIs for Xen page tables so that Xen page tables are mapped with
map_domain_page(). This is the first step towards removing the direct map. I implemented patches on top of Wei's to remove the direct map completely.Quoted 9 lines
In addition to Wei's, my patches:
- (Wei) implement a proper PMAP infrastructure for bootstrapping
- remove direct map code inmap_domain_page()and use mapcache, use PMAP when mapcache not ready
- map/unmap xenheap allocations to the direct map region so that va<->pa macros still work
- install dummy mappings (no permissions,INVALID_MFN) instead of actual 1:1 mappings during boot, so the direct map no longer exists
- fix many places where code incorrectly assumes a direct map
Quoted 2 lines
I am a bit confused. Are your patches fixing bug from Wei's series?
The goal is to remove the direct map completely from Xen. Wei's series has done the first step but was not complete. My additional patches finished the remaining steps and removed the direct map.
Quoted 8 lines
Quoted 5 lines
I have moderately tested the patches. I am able to boot into dom0, create/destroy PV/HVM guests and run XTF tests. Personally, I find it difficult to discover all places where it incorrectly assumes a direct map, so reviews and further testing are more than welcome.
Do you have a branch with this series applied?
I am setting this up. Will send out the link to the branch soon.
Quoted 2 lines
Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 24 lines · On 9/26/19 11:33 AM, [email protected] wrote:
Quoted 23 lines · Julien Grall
Hi,
Thank you for posting the series.
Quoted 17 lines · On 9/26/19 10:45 AM, [email protected] wrote:
From: Hongyan Xia <[email protected]>
Previously, Wei Liu has created the patch series to switch to alloc/map/unmap/free APIs for Xen page tables so that Xen page tables are mapped with
map_domain_page(). This is the first step towards removing the direct map. I implemented patches on top of Wei's to remove the direct map completely.In addition to Wei's, my patches:
- (Wei) implement a proper PMAP infrastructure for bootstrapping
- remove direct map code inmap_domain_page()and use mapcache, use PMAP when mapcache not ready
- map/unmap xenheap allocations to the direct map region so that va<->pa macros still work
- install dummy mappings (no permissions,INVALID_MFN) instead of actual 1:1 mappings during boot, so the direct map no longer exists
- fix many places where code incorrectly assumes a direct map
Quoted 4 lines
Quoted 2 lines
I am a bit confused. Are your patches fixing bug from Wei's series?
The goal is to remove the direct map completely from Xen. Wei's series has done the first step but was not complete. My additional patches finished the remaining steps and removed the direct map.
So I understand this correctly, Wei's series has no bug in it and could be committed as is without breaking Xen. Am I correct?
The reason I am asking that if you have a few patches that say fix leak/bug. If they are bug in Wei's series, then they should be squashed in patches introducing them.
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
I have moderately tested the patches. I am able to boot into dom0, create/destroy PV/HVM guests and run XTF tests. Personally, I find it difficult to discover all places where it incorrectly assumes a direct map, so reviews and further testing are more than welcome.
Do you have a branch with this series applied?
I am setting this up. Will send out the link to the branch soon.
Thank you.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines · Julien Grall
So I understand this correctly, Wei's series has no bug in it and could be committed as is without breaking Xen. Am I correct?
The reason I am asking that if you have a few patches that say fix leak/bug. If they are bug in Wei's series, then they should be squashed in patches introducing them.
My additional patches fixed several bugs found in Wei's series. If those fixes are folded in, Wei's series can be committed without breaking Xen.
So, it might make sense to commit Wei's series first with the fixes, then my extra series to actually remove the direct map.
Hongyan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel