All of lore.kernel.org
 help / color / mirror / Atom feed
From: <hongyax@amazon.com>
To: <xen-devel@lists.xenproject.org>
Cc: "Stefano Stabellini" <sstabellini@kernel.org>,
	"Wei Liu" <wl@xen.org>, "Hongyan Xia" <hongyax@amazon.com>,
	"George Dunlap" <George.Dunlap@eu.citrix.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>,
	"Ian Jackson" <ian.jackson@eu.citrix.com>,
	"Tim Deegan" <tim@xen.org>, "Julien Grall" <julien.grall@arm.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [RFC PATCH 58/84] x86/mm: fix leaks in map_xen_pagetable.
Date: Thu, 26 Sep 2019 10:46:21 +0100	[thread overview]
Message-ID: <6d79e6301ff15af71b21c64d10760abb9775b626.1569489002.git.hongyax@amazon.com> (raw)
In-Reply-To: <cover.1569489002.git.hongyax@amazon.com>

From: Hongyan Xia <hongyax@amazon.com>

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.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
 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(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index b2b2edbed1..145c5ab47c 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -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);
diff --git a/xen/common/vmap.c b/xen/common/vmap.c
index faebc1ddf1..fcdb8495c8 100644
--- a/xen/common/vmap.c
+++ b/xen/common/vmap.c
@@ -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;
diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index 262d92f18d..1b53429255 100644
--- a/xen/include/asm-arm/mm.h
+++ b/xen/include/asm-arm/mm.h
@@ -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))
diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h
index 906ec701a3..191de86bff 100644
--- a/xen/include/asm-x86/page.h
+++ b/xen/include/asm-x86/page.h
@@ -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__) */
 
diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h
index 369560e620..3d69727a9d 100644
--- a/xen/include/xen/vmap.h
+++ b/xen/include/xen/vmap.h
@@ -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)
-- 
2.17.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-09-26  9:51 UTC|newest]

Thread overview: 131+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26  9:45 [Xen-devel] [RFC PATCH 00/84] Remove direct map from Xen hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 01/84] x86/mm: defer clearing page in virt_to_xen_lXe hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 02/84] x86: move some xen mm function declarations hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 03/84] x86: introduce a new set of APIs to manage Xen page tables hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 04/84] x86/mm: introduce l{1, 2}t local variables to map_pages_to_xen hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 05/84] x86/mm: introduce l{1, 2}t local variables to modify_xen_mappings hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 06/84] x86/mm: map_pages_to_xen should have one exit path hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 07/84] x86/mm: add an end_of_loop label in map_pages_to_xen hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 08/84] x86/mm: make sure there is one exit path for modify_xen_mappings hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 09/84] x86/mm: add an end_of_loop label in modify_xen_mappings hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 10/84] x86/mm: change pl2e to l2t in virt_to_xen_l2e hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 11/84] x86/mm: change pl1e to l1t in virt_to_xen_l1e hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 12/84] x86/mm: change pl3e to l3t in virt_to_xen_l3e hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 13/84] x86/mm: rewrite virt_to_xen_l3e hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 14/84] x86/mm: rewrite xen_to_virt_l2e hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 15/84] x86/mm: rewrite virt_to_xen_l1e hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 16/84] x86/mm: switch to new APIs in map_pages_to_xen hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 17/84] xxx fixup: avoid shadowing mfn hongyax
2019-09-26 13:05   ` Wei Liu
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 18/84] x86/mm: drop lXe_to_lYe invocations in map_pages_to_xen hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 19/84] x86/mm: switch to new APIs in modify_xen_mappings hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 20/84] x86/mm: drop lXe_to_lYe invocations from modify_xen_mappings hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 21/84] x86/mm: switch to new APIs in arch_init_memory hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 22/84] x86_64/mm: introduce pl2e in paging_init hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 23/84] x86_64/mm: switch to new APIs " hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 24/84] x86_64/mm: drop l4e_to_l3e invocation from paging_init hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 25/84] x86_64/mm.c: remove code that serves no purpose in setup_m2p_table hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 26/84] x86_64/mm: introduce pl2e " hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 27/84] x86_64/mm: switch to new APIs " hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 28/84] x86_64/mm: drop lXe_to_lYe invocations from setup_m2p_table hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 29/84] efi: use new page table APIs in copy_mapping hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 30/84] efi: avoid using global variable " hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 31/84] efi: use new page table APIs in efi_init_memory hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 32/84] efi: add emacs block to boot.c hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 33/84] efi: switch EFI L4 table to use new APIs hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 34/84] x86/smpboot: add emacs block hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 35/84] x86/smpboot: clone_mapping should have one exit path hongyax
2019-09-26  9:45 ` [Xen-devel] [RFC PATCH 36/84] x86/smpboot: switch pl3e to use new APIs in clone_mapping hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 37/84] x86/smpboot: switch pl2e " hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 38/84] x86/smpboot: switch pl1e " hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 39/84] x86/smpboot: drop lXe_to_lYe invocations from cleanup_cpu_root_pgt hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 40/84] x86: switch root_pgt to mfn_t and use new APIs hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 41/84] x86/shim: map and unmap page tables in replace_va_mapping hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 42/84] x86_64/mm: map and unmap page tables in m2p_mapped hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 43/84] x86_64/mm: map and unmap page tables in share_hotadd_m2p_table hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 44/84] x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 45/84] x86_64/mm: map and unmap page tables in destroy_m2p_mapping hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 46/84] x86_64/mm: map and unmap page tables in setup_compat_m2p_table hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 47/84] x86_64/mm: map and unmap page tables in cleanup_frame_table hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 48/84] x86_64/mm: map and unmap page tables in subarch_init_memory hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 49/84] x86_64/mm: map and unmap page tables in subarch_memory_op hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 50/84] x86/smpboot: remove lXe_to_lYe in cleanup_cpu_root_pgt hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 51/84] x86/pv: properly map and unmap page tables in mark_pv_pt_pages_rdonly hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 52/84] x86/pv: properly map and unmap page table in dom0_construct_pv hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 53/84] x86: remove lXe_to_lYe in __start_xen hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 54/84] x86/mm: drop old page table APIs hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 55/84] x86: switch to use domheap page for page tables hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 56/84] x86/mm: drop _new suffix for page table APIs hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 57/84] x86: add Persistent Map (PMAP) infrastructure hongyax
2019-09-26  9:46 ` hongyax [this message]
2019-09-26 10:23   ` [Xen-devel] [RFC PATCH 58/84] x86/mm: fix leaks in map_xen_pagetable Julien Grall
2019-09-26 10:45     ` hongyax
2019-09-26 12:05       ` Julien Grall
2019-09-26 13:16   ` Wei Liu
2019-09-27 13:12     ` hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 59/84] x86/pmap: break the loop in pmap APIs hongyax
2019-09-26 13:21   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 60/84] x86/domain_page: use PMAP when d/vcache is not ready hongyax
2019-09-26 13:30   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 61/84] x86: lift domain mapcache to arch_domain hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 62/84] x86: lift vcpu mapcache to arch_vcpu hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 63/84] x86/domain_page: mapcache is no longer tied to pv hongyax
2019-09-26 13:59   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 64/84] mapcache: initialise the mapcache even for the idle domain hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 65/84] x86: fix some wrong assumptions on direct map. Increase PMAP slots to 8 hongyax
2019-09-26 14:08   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 66/84] x86/pv: domheap pages should be mapped while relocating initrd hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 67/84] x86/domain_page: remove direct map code and initialise idle mapcache hongyax
2019-09-26 14:14   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap hongyax
2019-09-26 10:39   ` Julien Grall
2019-09-26 10:45     ` Julien Grall
2019-09-26 10:52       ` hongyax
2019-09-26 11:18     ` hongyax
2019-09-26 12:24       ` Julien Grall
2019-09-26 13:03         ` hongyax
2019-09-26 13:22           ` Jan Beulich
2019-09-26 14:01           ` Julien Grall
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 69/84] page_alloc: comments on (un)mapping pages in xenheap allocations hongyax
2019-09-26 10:42   ` Julien Grall
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 70/84] x86/smpboot: use xenheap pages for rpts in smpboot hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 71/84] x86/setup: start tearing down the direct map hongyax
2019-09-26 10:50   ` Julien Grall
2019-09-26 14:26   ` Wei Liu
2019-09-27 12:54     ` hongyax
2019-09-27 13:00       ` Jan Beulich
2019-09-27 14:02         ` hongyax
2019-09-27 14:14           ` Jan Beulich
2019-09-27 14:49             ` hongyax
2019-09-27 15:01             ` hongyax
2019-09-27 13:01       ` Julien Grall
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 72/84] acpi: don't assume an always-mapped direct map in acpi allocations hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 73/84] x86/mm: Move vmap_to_mfn() to mm.c and rename to virt_to_mfn_walk() hongyax
2019-09-26 10:59   ` Julien Grall
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 74/84] x86/pv: refactor how building dom0 in PV handles domheap mappings hongyax
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 75/84] x86/mm: handle PSE early termination cases in virt_to_mfn_walk() hongyax
2019-09-26 14:39   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 76/84] x86/setup: also clear the permission bits in the dummy 1:1 mapping hongyax
2019-09-26 14:42   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 77/84] x86: properly (un)map pages in restore_all_guests hongyax
2019-09-26 14:52   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 78/84] Revert "x86/smpboot: use xenheap pages for rpts in smpboot." hongyax
2019-09-26 14:54   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 79/84] Don't assume bootmem_region_list is mapped. Also fix a double unmap bug hongyax
2019-09-26 11:21   ` Julien Grall
2019-09-26 12:36     ` hongyax
2019-09-26 12:51       ` Julien Grall
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 80/84] x86/setup: Install dummy 1:1 mappings for all mem passed to allocators hongyax
2019-09-26 15:47   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 81/84] x86/mm: optimise and properly unmap pages in virt_to_mfn_walk() hongyax
2019-09-26 15:46   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 82/84] x86: deduplicate code a bit and fix an unmapping bug hongyax
2019-09-26 15:48   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 83/84] x86/pmap: rewrite logic for locking hongyax
2019-09-26 15:50   ` Wei Liu
2019-09-26  9:46 ` [Xen-devel] [RFC PATCH 84/84] x86/pv: fix a couple of direct map assumptions in dom0 building hongyax
2019-09-26 15:51   ` Wei Liu
2019-09-26 10:21 ` [Xen-devel] [RFC PATCH 00/84] Remove direct map from Xen Julien Grall
2019-09-26 10:33   ` hongyax
2019-09-26 12:02     ` Julien Grall
2019-09-26 16:06       ` hongyax

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d79e6301ff15af71b21c64d10760abb9775b626.1569489002.git.hongyax@amazon.com \
    --to=hongyax@amazon.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.