xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Juergen Gross <jgross@suse.com>
Cc: minios-devel@lists.xenproject.org,
	xen-devel@lists.xenproject.org, wei.liu2@citrix.com
Subject: Re: [PATCH 14/22] mini-os: add map_frame_virt() function
Date: Wed, 24 Aug 2016 00:42:55 +0200	[thread overview]
Message-ID: <20160823224255.GI4401@var.home> (raw)
In-Reply-To: <1471965368-6159-15-git-send-email-jgross@suse.com>

Juergen Gross, on Tue 23 Aug 2016 17:16:00 +0200, wrote:
> Add a function map_frame_virt() to map a given frame and return its
> virtual address.
> 
> On arm we just use the frame physical address, while on x86 we take a
> page from the virtual kernel area. For this purpose make this area
> available even in case of undefined CONFIG_BALLOON.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/balloon.c    |  2 --
>  arch/arm/mm.c         |  5 +++++
>  arch/x86/balloon.c    | 13 ++++---------
>  arch/x86/mm.c         | 23 +++++++++++++++++++++++
>  balloon.c             |  9 ++++-----
>  include/balloon.h     |  1 -
>  include/mm.h          |  1 +
>  include/x86/arch_mm.h |  1 +
>  8 files changed, 38 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/arm/balloon.c b/arch/arm/balloon.c
> index 958ecba..1df7d1c 100644
> --- a/arch/arm/balloon.c
> +++ b/arch/arm/balloon.c
> @@ -25,8 +25,6 @@
>  
>  #ifdef CONFIG_BALLOON
>  
> -unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
> -
>  void arch_pfn_add(unsigned long pfn, unsigned long mfn)
>  {
>  }
> diff --git a/arch/arm/mm.c b/arch/arm/mm.c
> index 4f58fc7..dbde162 100644
> --- a/arch/arm/mm.c
> +++ b/arch/arm/mm.c
> @@ -141,3 +141,8 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
>  
>      return to_virt(gnttab_table);
>  }
> +
> +unsigned long map_frame_virt(unsigned long mfn)
> +{
> +    return mfn_to_virt(mfn);
> +}
> diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c
> index 16aaae4..10b440c 100644
> --- a/arch/x86/balloon.c
> +++ b/arch/x86/balloon.c
> @@ -29,9 +29,6 @@
>  #include <mini-os/paravirt.h>
>  
>  #ifdef CONFIG_BALLOON
> -
> -unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
> -
>  #ifdef CONFIG_PARAVIRT
>  static void p2m_invalidate(unsigned long *list, unsigned long start_idx)
>  {
> @@ -53,7 +50,7 @@ static inline unsigned long *p2m_to_virt(unsigned long p2m)
>  
>  void arch_remap_p2m(unsigned long max_pfn)
>  {
> -    unsigned long pfn;
> +    unsigned long pfn, new_p2m;
>      unsigned long *l3_list, *l2_list, *l1_list;
>  
>      l3_list = p2m_l3list();
> @@ -67,17 +64,15 @@ void arch_remap_p2m(unsigned long max_pfn)
>      if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) )
>          return;
>  
> +    new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages));
>      for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
>      {
> -        map_frame_rw(virt_kernel_area_end + PAGE_SIZE * (pfn / P2M_ENTRIES),
> +        map_frame_rw(new_p2m + PAGE_SIZE * (pfn / P2M_ENTRIES),
>                       virt_to_mfn(phys_to_machine_mapping + pfn));
>      }
>  
> -    phys_to_machine_mapping = (unsigned long *)virt_kernel_area_end;
> +    phys_to_machine_mapping = (unsigned long *)new_p2m;
>      printk("remapped p2m list to %p\n", phys_to_machine_mapping);
> -
> -    virt_kernel_area_end += PAGE_SIZE * p2m_pages(nr_max_pages);
> -    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
>  }
>  
>  int arch_expand_p2m(unsigned long max_pfn)
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index f5248a4..762599d 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -57,6 +57,7 @@ unsigned long mfn_zero;
>  pgentry_t *pt_base;
>  static unsigned long first_free_pfn;
>  static unsigned long last_free_pfn;
> +static unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
>  
>  extern char stack[];
>  extern void page_walk(unsigned long va);
> @@ -829,3 +830,25 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
>      HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
>      return map_frames(frames, nr_grant_frames);
>  }
> +
> +unsigned long alloc_virt_kernel(unsigned n_pages)
> +{
> +    unsigned long addr;
> +
> +    addr = virt_kernel_area_end;
> +    virt_kernel_area_end += PAGE_SIZE * n_pages;
> +    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
> +
> +    return addr;
> +}
> +
> +unsigned long map_frame_virt(unsigned long mfn)
> +{
> +    unsigned long addr;
> +
> +    addr = alloc_virt_kernel(1);
> +    if ( map_frame_rw(addr, mfn) )
> +        return 0;
> +
> +    return addr;
> +}
> diff --git a/balloon.c b/balloon.c
> index 8669edb..b0d0230 100644
> --- a/balloon.c
> +++ b/balloon.c
> @@ -50,20 +50,19 @@ void get_max_pages(void)
>  
>  void mm_alloc_bitmap_remap(void)
>  {
> -    unsigned long i;
> +    unsigned long i, new_bitmap;
>  
>      if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) )
>          return;
>  
> +    new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3));
>      for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE )
>      {
> -        map_frame_rw(virt_kernel_area_end + i,
> +        map_frame_rw(new_bitmap + i,
>                       virt_to_mfn((unsigned long)(mm_alloc_bitmap) + i));
>      }
>  
> -    mm_alloc_bitmap = (unsigned long *)virt_kernel_area_end;
> -    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> 3);
> -    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
> +    mm_alloc_bitmap = (unsigned long *)new_bitmap;
>  }
>  
>  #define N_BALLOON_FRAMES 64
> diff --git a/include/balloon.h b/include/balloon.h
> index 8cd41af..6cfec4f 100644
> --- a/include/balloon.h
> +++ b/include/balloon.h
> @@ -33,7 +33,6 @@
>  #define BALLOON_EMERGENCY_PAGES   64
>  
>  extern unsigned long nr_max_pages;
> -extern unsigned long virt_kernel_area_end;
>  extern unsigned long nr_mem_pages;
>  
>  void get_max_pages(void);
> diff --git a/include/mm.h b/include/mm.h
> index 953570c..4fc364f 100644
> --- a/include/mm.h
> +++ b/include/mm.h
> @@ -79,6 +79,7 @@ int do_map_frames(unsigned long addr,
>  	unsigned long increment, domid_t id, int *err, unsigned long prot);
>  int unmap_frames(unsigned long va, unsigned long num_frames);
>  int map_frame_rw(unsigned long addr, unsigned long mfn);
> +unsigned long map_frame_virt(unsigned long mfn);
>  #ifdef HAVE_LIBC
>  extern unsigned long heap, brk, heap_mapped, heap_end;
>  #endif
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index e0ae552..9372f1e 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -277,6 +277,7 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
>  
>  pgentry_t *need_pgt(unsigned long addr);
>  void arch_mm_preinit(void *p);
> +unsigned long alloc_virt_kernel(unsigned n_pages);
>  
>  #endif
>  
> -- 
> 2.6.6
> 

-- 
Samuel
After watching my newly-retired dad spend two weeks learning how to make a new
folder, it became obvious that "intuitive" mostly means "what the writer or
speaker of intuitive likes".
(Bruce Ediger, bediger@teal.csn.org, in comp.os.linux.misc, on X the
intuitiveness of a Mac interface.)

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

  reply	other threads:[~2016-08-23 22:42 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
2016-08-23 15:15 ` [PATCH 01/22] mini-os: resync xen headers Juergen Gross
2016-08-23 19:44   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 02/22] mini-os: make dump_regs() work in early boot Juergen Gross
2016-08-23 19:44   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 03/22] mini-os: add CONFIG_PARAVIRT Juergen Gross
2016-08-23 19:54   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 04/22] mini-os: make some memory management related macros usable from assembler Juergen Gross
2016-08-23 19:46   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 05/22] mini-os: add boot code for HVMlite support Juergen Gross
2016-08-23 20:51   ` Samuel Thibault
2016-08-24  5:13     ` Juergen Gross
2016-08-23 15:15 ` [PATCH 06/22] mini-os: setup hypercall page for HVMlite Juergen Gross
2016-08-23 21:03   ` Samuel Thibault
2016-08-24  5:10     ` Juergen Gross
2016-08-23 15:15 ` [PATCH 07/22] mini-os: support hvm_op hypercall Juergen Gross
2016-08-23 22:00   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 08/22] mini-os: initialize trap handling for HVMlite Juergen Gross
2016-08-23 22:05   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 09/22] mini-os: support HVMlite traps Juergen Gross
2016-08-23 22:10   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT Juergen Gross
2016-08-23 22:20   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite Juergen Gross
2016-08-23 22:27   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 12/22] mini-os: add x86 native page table handling Juergen Gross
2016-08-23 22:40   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size Juergen Gross
2016-08-23 19:49   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 14/22] mini-os: add map_frame_virt() function Juergen Gross
2016-08-23 22:42   ` Samuel Thibault [this message]
2016-08-23 15:16 ` [PATCH 15/22] mini-os: setup console interface parameters Juergen Gross
2016-08-23 22:44   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 16/22] mini-os: setup xenbus " Juergen Gross
2016-08-23 22:45   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 17/22] mini-os: add get_cmdline() function Juergen Gross
2016-08-23 23:03   ` [Minios-devel] " Samuel Thibault
2016-08-23 15:16 ` [PATCH 18/22] mini-os: map shared info page for HVMlite Juergen Gross
2016-08-23 22:47   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 19/22] mini-os: remove using start_info in architecture independent code Juergen Gross
2016-08-23 22:48   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 20/22] mini-os: print start of day messages depending on domain type Juergen Gross
2016-08-23 22:51   ` Samuel Thibault
2016-08-24  5:09     ` Juergen Gross
2016-08-23 15:16 ` [PATCH 21/22] mini-os: get physical memory map Juergen Gross
2016-08-23 22:58   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 22/22] mini-os: support idle for HVMlite Juergen Gross
2016-08-23 23:01   ` Samuel Thibault

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=20160823224255.GI4401@var.home \
    --to=samuel.thibault@ens-lyon.org \
    --cc=jgross@suse.com \
    --cc=minios-devel@lists.xenproject.org \
    --cc=wei.liu2@citrix.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).